How do I make the = operator format code with an external tool like gofmt or black?
:set equalprg=gofmt
By default, Vim's = operator re-indents text using its internal rules.
config #config #editing #ex-commands #formatting #indentation
:set equalprg=gofmt
By default, Vim's = operator re-indents text using its internal rules.
config #config #editing #ex-commands #formatting #indentation
:s/\v\w+/\U&/g
Vim's substitute command supports special case-conversion sequences in the replacement string, letting you transform matched text to upper or lower case without
!{motion}{cmd}<CR>
In normal mode, !{motion} sends the lines covered by the motion to a shell command's stdin and replaces them with stdout.
:filter /pattern/ {command}
:filter /pattern/ {command} runs any Ex command but suppresses every output line that does not match the pattern.
:sort n
:sort n sorts lines by the first number found on each line, comparing values numerically rather than as strings.
:helpgrep
:helpgrep {pattern} searches all installed Vim help files for a pattern and populates the quickfix list with every match.
:Subvert
The vim-abolish plugin's :Subvert command (abbreviated :S) substitutes a word across all its case variants simultaneously.
:mksession
:mksession saves a snapshot of the current Vim session — all open buffers, window splits, tab pages, cursor positions, and folds — to a file called Session.
:w !diff % -
The command :w !diff % - pipes the current buffer's contents to an external diff command that compares it against the saved file on disk.
buffers-windows #buffers-windows #ex-commands #editing #navigation
:[range]norm @{register}
The :normal command executes normal-mode keystrokes on each line in a range — including macro playback.
:center, :right, :left
Vim includes three built-in Ex commands for text alignment that most users never discover: :center, :right, and :left.
<C-\>e
Pressing e on the command line opens a special prompt that lets you type a Vimscript expression.
command-line #command-line #ex-commands #vimscript #insert-mode
:command
:command lets you define new Ex (colon-prefixed) commands with custom names, optional argument handling, and completion.
command-line #command-line #ex-commands #config #normal-mode
:%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.
:set autochdir
The autochdir option tells Vim to automatically change the current working directory to the directory of the file in the active window whenever you switch buffe
:keeppatterns {cmd}
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
:sp +/{pattern} {file}
The +{cmd} syntax lets you run an Ex command immediately after a file is opened.
:put ={expr}
The :put ={expr} command evaluates a Vimscript expression and inserts the result as a new line below the cursor.
:Subvert/{src}/{tgt}/g
vim-abolish provides :Subvert, a smarter substitute that detects and preserves the case style of each match.
:tab {cmd}
Most commands that open a new window (:help, :split, :new, :terminal) open a horizontal split by default.