4 releases (breaking)

Uses new Rust 2024

new 0.4.0 Nov 4, 2025
0.3.0 Jul 27, 2025
0.2.0 Jul 27, 2025
0.1.0 Jul 22, 2025

#1281 in Filesystem

MIT license

345KB
2.5K SLoC

Live Action Search and Replace (LASR)

When performing a global search-and-replace using e.g. sed, it can be difficult to hone in on the exact correct pattern. lasr makes this easier by showing live results as you type.

Example of using lasr

Installation

Binary artifacts can be downloaded from the releases page.

If you have a rust toolchain, you can install from source:

cargo install lasr

Usage

Simply run lasr to start a search-and-replace in the current directory. You may run lasr <path> [<path>...] to search a specific directories or files. This will open a TUI where you can start typing a search pattern and see live matches below. Once you are happy with the search pattern, press Tab to start editing the replacement pattern. Finally, press Enter to confirm and execute the replacement, or Esc to cancel the replacement. You can press Ctrl+S to toggle case-insensitive searching, or pass the -i flag to enable case-insensitive search on startup.

Syntax

The pattern syntax is based on the rust regex crate. The replacement syntax is based on the replace method in that crate.

Replacements may reference numbered groups as $1 or ${1}, or named groups like $foo or ${foo}. The {} brackets may be necessary to separate the replacement from other text. $0 or ${0} refers to the entire match.

Configuration

The configuration file is located at $XDG_CONFIG_HOME/lasr/lasr.toml (~/.config/lasr/lasr.toml by default). The current configuration can be printed by running lasr --dump-config. This can be used as a starting point to edit your own configuration:

lasr --dump-config > ~/.config/lasr/lasr.toml

Default Config

[theme.base]
fg = "Reset"

[theme.find]
fg = "Red"
add_modifier = "CROSSED_OUT"

[theme.replace]
fg = "Green"
add_modifier = "BOLD"

[keys]
c-b = "cursor_left"
c-s = "toggle_ignore_case"
tab = "toggle_search_replace"
left = "cursor_left"
home = "cursor_home"
c-e = "cursor_end"
c-d = "delete_char"
right = "cursor_right"
c-h = "delete_char_backward"
enter = "confirm"
backspace = "delete_char_backward"
c-k = "delete_to_end_of_line"
c-a = "cursor_home"
end = "cursor_end"
c-f = "cursor_right"
c-c = "exit"
esc = "exit"
c-u = "delete_line"
c-w = "delete_word"

General Config

The following settings may be placed at the top-level of the config, not under any section:

Key Description Default
threads Threads to use, 0 to auto-select 0
auto_pairs Auto-insert mathching pairs of ({[ true

Theme Config

The theme section of the config includes 3 "style" sub-sections:

Key Description
base Most text/UI
find Text matched by the pattern
replace Replacement text

A "style" has the following attributes

Key Description
fg Foreground color
bg Background color
add_modifier Add modifiers
sub_modifier Remove modifiers

A color can be an ANSI color name like "red", an ANSI 8-bit color index like "7", or a hex string like "#00FF00".

add_modifier and sub_modifier can be one of the following:

  • "BOLD"
  • "DIM"
  • "ITALIC"
  • "UNDERLINED"
  • "SLOW_BLINK"
  • "RAPID_BLINK"
  • "REVERSED"
  • "HIDDEN"
  • "CROSSED_OUT"

Keys Config

The keys section specifies key bindings. Each key is a single character or key name, optionally followed by "c-" and/or "a-" to specify a ctrl or alt modifier. The following are valid key names:

  • a-z, 0-9
  • f0-f12
  • backspace
  • enter
  • left
  • right
  • up
  • down
  • home
  • end
  • pageup
  • pagedown
  • tab
  • backtab
  • delete
  • insert
  • esc

Each value in the keys section is one of the following actions:

Action Description Default Key Binding
noop Do nothing, used to unbind a default key
exit Exit without performing any replacement Esc, Ctrl+C
confirm Exit and perform replacements Enter
toggle_search_replace Switch focus between the "search" and "replace" inputs Tab
toggle_ignore_case Toggle ignore case flag Ctrl+S
cursor_left Move cursor left one character , Ctrl+B
cursor_right Move cursor right one character , Ctrl+F
cursor_home Move cursor to beginning of line Home, Ctrl+A
cursor_end Move cursor to end of line End, Ctrl+E
delete_char Delete character at cursor position Ctrl+D
delete_char_backward Delete character before cursor (backspace) Backspace, Ctrl+H
delete_word Delete word before cursor Ctrl+W
delete_to_end_of_line Delete from cursor to end of line Ctrl+K
delete_line Delete entire line Ctrl+U

Troubleshooting

Logs are located at $XDG_CACHE_HOME/lasr/log.txt. Log verbosity can be increased by setting the environment variable RUST_LOG to debug or trace. See env_logger for more info.

Other cool search/replace tools

  • sad allows you to approve/reject each replacement, but must be re-run each time you change the pattern.
  • sd provides a simpler CLI alternative to sed, but is not interactive.
  • ast-grep is like sed/grep, but using tree-sitter to match code syntax.

Dependencies

~35–51MB
~1M SLoC