How do I run a global command only on lines within a visual selection?
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
qa:s/old/new/g<CR>jq
How it works You can combine Ex commands like :s (substitute) with macro recording to create powerful repeatable find-and-replace operations that go beyond what
:Telescope live_grep
Telescope's livegrep picker provides real-time regex search across your entire project as you type.
:%s/pattern/\=MyFunc(submatch(0))/g
The \= prefix in Vim's substitute replacement invokes the expression register, which can call any Vimscript function.
:%s/pattern/\=@0/g
The \=@0 replacement expression inserts the contents of register 0 (last yank) as the replacement text.
/pattern/+N or /pattern/-N
Vim's search command accepts an offset that places your cursor on a line relative to the match.
/\%>10l\%<20lpattern
Vim's \%>Nl and \%10l matches only after line 10 \%10l\%10l\%<20lold/new/g Combine with column restrictions for precise region targeting Tips Line numbers in \%
qq /pattern<CR> {commands} q
By incorporating a search command inside a macro, you can make it jump to the next occurrence of a pattern before performing its edits.
/\(pattern\)\@<=target or /target\(pattern\)\@=
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
:set incsearch hlsearch
The combination of incsearch and hlsearch gives you live, interactive search highlighting.
:vimgrep /pattern/g **/*.ext
The :vimgrep command searches for a pattern across multiple files and loads the results into the quickfix list.
* then :%s//new/g
Pressing searches for the word under the cursor, which also loads it into the search register.
:'<,'>s/\%Vold/new/g
The \%V atom restricts a search pattern to match only within the visual selection area, including visual block selections.
:%s/\<word\>/\u&/g
Vim's substitute command supports case conversion modifiers in the replacement string.
<C-r>/
Vim stores your last search pattern in the / register.
g&
The g& command repeats the last substitute command across the entire file.
:cdo s/old/new/g | update
The :cdo command executes a given command on every entry in the quickfix list.
command-line #command-line #quickfix #batch-editing #search #multi-file
s{char}{char}
The vim-sneak plugin by Justin Keyes provides a motion that lets you jump to any visible location by typing just two characters.
:Rg
The fzf.
:%Subvert/old/new/g
The vim-abolish plugin by Tim Pope provides the :Subvert command (abbreviated :S), which performs search-and-replace operations that automatically handle every