How do I filter text through an external program using a motion in normal mode?
!{motion}{program}
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
!{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.
: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 \=.
: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.
:packadd {package}
Vim ships with several useful packages in its opt/ directory that are not loaded by default.
:profile start profile.log
When Vim feels sluggish, the built-in :profile command lets you measure exactly how much time each script and function consumes.
:keeppattern s/old/new/g
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
:tag /pattern
When working with ctags, you typically jump to exact tag names with .
:g/pattern/z#.5
The :global command is great for finding lines matching a pattern, but by default it only shows the matching lines themselves.
/\(\<\w\+\>\)\_s\+\1\>
When writing or editing text, repeated words like "the the" or "is is" are a common typo that spell checkers often miss.
:/start/,/end/d
Instead of specifying line numbers for Ex command ranges, you can use search patterns.
command-line #ex-commands #editing #search #ranges #command-line
:vimgrep /pattern/j **/*
By default, :vimgrep jumps your cursor to the first match it finds, which can be disorienting when you just want to collect results and browse them on your own
:keeppattern {cmd}
Many Ex commands silently overwrite the search register (@/), which changes your hlsearch highlighting and n/N behavior.
:diffget / :diffput
When comparing two files side by side with :diffsplit or vim -d, you often want to pull specific changes from one file into another rather than accepting all di
:undojoin
When writing Vim scripts or running multiple Ex commands, each command normally creates a separate undo entry.
:vimgrep /pattern/ %
When you need to find all occurrences of a pattern in the current file and jump between them systematically, :vimgrep with % is more powerful than basic / searc
:.+1,.+3d
Vim's Ex command addresses support arithmetic offsets relative to the current line (.
command-line #ex-commands #editing #navigation #command-line