How do you print all lines matching a pattern?
:g/pattern/p
Use :g/pattern/p to print all matching lines.
795 results for "g* g#"
:g/pattern/p
Use :g/pattern/p to print all matching lines.
:%s/; /;\r/g
In the replacement part, use \r to insert a newline.
:tabdo %s/old/new/g
Use :tabdo to execute a command in every tab page.
:bufdo %s/old/new/g
Use :bufdo to execute a command in every buffer.
g<C-g>
While shows basic file info (filename, line count, position), g provides a much more detailed statistical breakdown of your file or visual selection.
qaq:g/pattern/normal "Ayy
Clear register a with qaq, then use :g/pattern/normal "Ayy to append all matching lines to register a.
:Git or :G
vim-fugitive provides Git integration.
:%s/\d\+/\=submatch(0)*2/g
Use \= to evaluate expressions.
g* and g#
The and # commands search for the exact whole word under the cursor (with word boundaries \).
g<C-g> (visual mode)
In visual mode, pressing g reports detailed statistics for the selected text only — word count, character count, and byte count.
:g/pattern1/g/pattern2/command
Vim's :g command can be nested — the command part of one :g can itself be another :g.
qaI| <Esc>:s/,/ | /g\nA |<Esc>jq
Record a macro that adds pipe delimiters around CSV fields, converting each line to a Markdown table row format.
:%s/<C-r>a/replacement/g
In command-line mode, a inserts the contents of register a.
qa:s/\t/ /g\njq
Record a macro that substitutes all tabs with spaces on the current line, then moves down.
:g/pattern1/s/pattern2/replacement/g
Combining :g with :s lets you apply a substitution using two independent patterns: :g selects which lines to act on, and :s controls what gets replaced within t
g- and g+
Vim's undo history is a tree, not a linear stack.
:g/outer/,/end/g/inner/
The :global command accepts a range, which lets you scope its search to sections of the file rather than the entire buffer.
:g/pattern/cmd1 | cmd2
The :g (global) command can execute multiple Ex commands per matching line by chaining them with .
command-line #command-line #global #ex-commands #batch-editing #advanced
g^ and g$
When wrap is on, long lines wrap visually across multiple screen lines.
g; / g,
The g; and g, commands let you navigate Vim's changelist — a per-buffer history of every position where you made a change.
navigation #navigation #changelist #editing #normal-mode #marks