How do I search and replace with confirmation for each match?
:%s/old/new/gc
Adding the c flag to a substitute command makes Vim pause at every match and ask you whether to replace it.
:%s/old/new/gc
Adding the c flag to a substitute command makes Vim pause at every match and ask you whether to replace it.
:%s/pattern/\=expression/g
Vim's substitute command supports expression replacements using \= in the replacement string.
ciw""<Esc>P
Vim doesn't have a built-in "surround" operator, but you can wrap any word in quotes or brackets with a short sequence: ciw""P.
editing #editing #text-objects #normal-mode #productivity #surround
viwp
The viwp command visually selects the word under the cursor and replaces it with the contents of the unnamed register (your last yank or delete).
visual-mode #editing #visual-mode #registers #paste #productivity
:tabnew / gt / gT
Vim's tab pages let you organize your workspace into separate views, each containing its own window layout.
buffers-windows #buffers #windows #tabs #navigation #productivity
<C-^>
Pressing (Ctrl-6 on most keyboards) instantly toggles between the current buffer and the alternate file — the last file you were editing.
buffers-windows #navigation #buffers #normal-mode #productivity #windows
g~iw
The g~iw command toggles the case of every character in the word under the cursor — uppercase letters become lowercase and vice versa.
:earlier {time} / :later {time}
Vim's :earlier and :later commands let you navigate the undo history by wall-clock time rather than by individual undo steps.
editing #editing #undo-redo #ex-commands #advanced #productivity
g- / g+
Vim doesn't have a simple linear undo stack — it maintains a full undo tree with branches.
editing #editing #undo-redo #normal-mode #advanced #productivity
/\v
Vim's default regex syntax requires backslashes before most special characters like +, (, ), {, and , which is the opposite of what most developers expect from
:vimgrep /pattern/ **/*.ext | copen
The :vimgrep command searches for a regex pattern across multiple files and populates the quickfix list with every match.
search #search #quickfix #ex-commands #navigation #productivity #grep
<C-v>jjc replacement<Esc>
Visual block mode's change command lets you replace a rectangular column of text across multiple lines in a single operation.
visual-mode #editing #visual-mode #block-mode #normal-mode #productivity
v + repeated iw/aw/i(/a(/ip/ap
Once you enter visual mode, you can progressively expand your selection by typing increasingly larger text objects.
visual-mode #visual-mode #text-objects #editing #selection #productivity
let @a = 'macro_contents'
Recorded macros are stored in registers, which are lost when you quit Vim (unless viminfo saves them).
zt
The zt command repositions the viewport so that the line where your cursor sits moves to the top of the screen, without changing your cursor position within the
navigation #navigation #scrolling #normal-mode #viewport #productivity
:windo set scrollbind
The scrollbind option locks two or more windows together so that scrolling in one window automatically scrolls the others by the same amount.
buffers-windows #windows #navigation #splits #diff #productivity
/foo\_.*bar
Vim's default .
:args **/*.py | argdo %s/old/new/gc | update
Vim can perform search-and-replace across multiple files without any plugins by combining the arglist with :argdo.
search #search #substitution #ex-commands #productivity #quickfix #arglist
/pattern/+3
Vim's search command accepts an offset after the pattern that shifts where the cursor lands relative to the match.
/\%Vpattern
The \%V atom restricts a search pattern to only match inside the most recent visual selection.