How do I ignore whitespace changes when using Vim's diff mode?
:set diffopt+=iwhite
When comparing files in Vim's diff mode, whitespace-only changes (extra spaces, changed indentation) can clutter the diff and hide meaningful edits.
:set diffopt+=iwhite
When comparing files in Vim's diff mode, whitespace-only changes (extra spaces, changed indentation) can clutter the diff and hide meaningful edits.
qQ...q
When you record a macro into register q with qq.
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
v{motion}<C-g>
Vim has a lesser-known select mode that behaves like selection in typical GUI editors: any typed character replaces the selection.
:g/pattern/m0
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
command-line #global #move #ex-commands #editing #command-line
:compiler gcc | :make
Vim ships with built-in compiler plugins that configure makeprg and errorformat for popular tools.
:m +1
The :move command (abbreviated :m) relocates lines to a new position in the buffer without touching any registers.
:%sort /[^,]*,/ n
Vim's :sort command accepts a pattern that controls which part of each line is used as the sort key.
:keeppattern %s/pattern/replacement/g
When you run a :substitute command, Vim updates the search register (@/) with the substitute pattern, which changes your hlsearch highlighting and affects n/N n
!{motion}{program}
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
:g/pattern/.-1,.+1d
The :g (global) command normally operates on lines that match a pattern.
grn / grc / grm
Neovim's nvim-treesitter plugin provides incremental selection based on the abstract syntax tree (AST) of your code.
:cexpr system('grep -rn TODO .')
The :cexpr command evaluates an expression and parses the result as quickfix entries using the current errorformat.
:%s/^/\=line('.').' '/
Vim's substitute command supports expressions in the replacement string using \=.
<C-v>jjlU
Visual block mode lets you select rectangular regions of text, which means you can target a specific column and apply case changes only to that area.
=i{
When editing code with messy indentation — after a paste, a merge conflict, or a refactor — you often need to fix just one block rather than the entire file
:let @a = substitute(@a, 'old', 'new', 'g')
After recording a macro or yanking text into a named register, you may need to tweak it — fix a typo in a recorded macro, change a variable name in yanked tex
:s/^/\=line('.') - line("'<") + 1 . '. '/
When you need to quickly number a set of lines — such as TODO items, steps, or bullet points — you can use a visual selection combined with a substitution e
visual-mode #visual-mode #editing #ex-commands #formatting #substitute
:g/pattern/m 0
The :global command combined with :move lets you restructure a file by relocating all lines that match a pattern.
:diffthis
You often have two files open side by side and want to compare them without leaving Vim or launching vimdiff.