How do I use a Vimscript expression as the replacement in a substitute command?
:%s/pattern/\=expr/g
Prefixing the replacement field of :s with \= tells Vim to evaluate the rest as a Vimscript expression and use its result as the replacement string.
:%s/pattern/\=expr/g
Prefixing the replacement field of :s with \= tells Vim to evaluate the rest as a Vimscript expression and use its result as the replacement string.
:keepjumps {cmd}
:keepjumps is a command modifier that suppresses any jump list updates caused by the command that follows it.
<C-y> (above) / <C-e> (below)
In insert mode, inserts the character from the same column one line above, and inserts the character from the same column one line below.
!{motion}{cmd}
The ! operator in normal mode lets you pipe any motion's text through a shell command and replace it with the output.
editing #editing #shell #external-command #normal-mode #filtering
!{motion} {cmd}
The ! operator passes text selected by a motion through an external shell command, replacing it with the command's output.
gI
Most Vim users know I to insert at the start of a line — but I actually jumps to the first non-blank character, skipping leading whitespace.
d/{pattern}<CR>
Vim lets you use a / search as a motion for any operator.
=G
The =G command applies Vim's auto-indent operator (=) from the current line to the last line of the file (G).
gR
gR enters Virtual Replace mode, a smarter variant of Replace mode (R) that replaces characters based on screen columns rather than raw bytes.
<C-e> / <C-y> (insert mode)
In insert mode, copies the character directly below the cursor (from the next line) and copies the character directly above (from the previous line).
:%!command
:%!{command} replaces the entire buffer contents with the output of piping them through a shell command.
gwip
The gw operator reformats text just like gq, but leaves the cursor in its original position after reformatting.
<C-v>u{hex}
In insert mode, pressing followed by u and a 4-digit hexadecimal codepoint inserts the corresponding Unicode character directly into the buffer.
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
<C-y> and <C-e>
In Insert mode, copies the character at the same column position from the line above the cursor, and copies the character from the line below.
:%s/pattern/\U&/g
Vim's substitute replacement string supports special case-transform atoms that change the case of matched text without requiring a second pass or an external to
<C-a> (insert mode)
While in insert mode, pressing re-inserts the exact text you typed during your previous insert session.
:earlier
Vim's undo history is not just a linear list of changes — it records timestamps too.
!{motion}{command}
The ! operator filters the text covered by a motion through an external shell command, replacing the original lines with the command's stdout.
[p
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.