How do I auto-indent an entire file in Vim?
gg=G
The gg=G command re-indents every line in the current file according to Vim's indentation rules.
795 results for "g* g#"
gg=G
The gg=G command re-indents every line in the current file according to Vim's indentation rules.
:g/^/normal I// <CR>
When you need to comment a whole block quickly, :global combined with :normal is faster than recording a macro or entering Visual Block mode.
g<
Pressing g or q to dismiss it again Example Tips :messages also shows recent messages (and those accumulate across the session), while g< only shows the last pa
g<C-x>
Most people know decrements one number under the cursor, but g in Visual mode performs a sequential decrement across the selection.
:%s/0x\x\+/\=str2nr(submatch(0), 16)/g
When cleaning logs, protocol dumps, or generated code, you may need to normalize 0x.
g'{mark}
Vim's standard mark-jump commands ('a, ` a `) always add the current position to the jumplist before leaping to the mark.
:/start/,/end/s/pattern/replacement/g
You can restrict a substitution to a range defined by two patterns.
:g/[^[:space:]]/normal! A;\<CR>
When you need to patch many lines at once, :g with :normal! is often faster and safer than recording a macro.
command-line #command-line #ex-commands #editing #normal-mode
:keepjumps normal! gg=G
Bulk formatting commands are common in cleanup sessions, but they often leave side effects in your navigation history.
:g/pattern/.,+2d
Inside a :global command, .
command-line #ex-commands #global #delete #editing #command-line
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:g/pattern/y A
The :g/pattern/y A command yanks every line matching the pattern and appends it to register a.
command-line #command-line #registers #global #ex-commands #filtering
:G log -- %
vim-fugitive's :G log -- % loads the git commit history for the current file into a quickfix-style log buffer.
:g/^$/d
The :g/^$/d command deletes every blank line in the file using Vim's powerful global command.
:g/./norm @q
Combining the :global command with :normal lets you run a macro on every non-blank line in one shot.
: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
g]
g] is the disambiguation-aware alternative to .
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
g-
Vim's undo history is a tree, not a linear stack.
:set gdefault
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.