The g Family

30+ commands hide behind the g prefix.

Keys: gd, gf, gv, gi, gq, g;, g,, g~, gU, gu

g opens a second keymap containing extended versions of familiar commands and unrelated commands that needed more keyboard space. It is useful as an index, but it does not obey one universal rule.

The g prefix opens a second keymap of roughly thirty commands. Many are extended versions of familiar ideas: screen-line motions, case operators, jumps, formatting, and navigation. Others simply needed an available two-key spelling. There is no rule from which you can derive every g command, so treat this chapter as an organized index rather than a new grammar.

Reference (most-used)

Key Action
gd Go to local definition under cursor
gD Go to global definition
gf Open file under cursor
gF Open file under cursor at line :{n}
gv Re-select last visual mode selection (see Visual Mode in Depth)
gi Insert at the last insert mode position
g; Previous change position
g, Next change position
ge Back to end of previous word
gE Back to end of previous WORD
gj / gk Down/up by display line (matters with wrap)
g0 Display start of line
g^ Display first non-blank
g_ Last non-blank of line
gU{motion} Uppercase operator
gu{motion} Lowercase operator
g~{motion} Toggle case operator
gq{motion} Reformat (line-wrap) operator
g@{motion} Call user operatorfunc (advanced)
ga Show character info under cursor (also g8)
gx Open URL under cursor in browser
g< Re-show last command-line output
gn Enter visual mode on the next search match (see Visual Mode in Depth)
gN Enter visual mode on the previous search match (see Visual Mode in Depth)
gp / gP Like p/P, but cursor lands after pasted text
gt / gT Next / previous tab
gr{c} Replace (virtual) โ€” see *Replace Mode*
gR Virtual replace mode
go Go to byte {n}
g?{motion} ROT13 the range (yes, really)

Worked example โ€” gU gu g~ ga

The 'g' prefix is a grab-bag of useful commands.

Step 1 ยท
[missing screenshot prefix.g/frame_01.color.svg โ€” run python content/render_screenshots.py]
Step 2 ยท gUiw ยท gUiw โ€” uppercase inner word.
[missing screenshot prefix.g/frame_02.color.svg โ€” run python content/render_screenshots.py]
Step 3 ยท guiw ยท guiw โ€” lowercase inner word.
[missing screenshot prefix.g/frame_03.color.svg โ€” run python content/render_screenshots.py]
Step 4 ยท g~iw ยท g~iw โ€” toggle case of inner word.
[missing screenshot prefix.g/frame_04.color.svg โ€” run python content/render_screenshots.py]
Step 5 ยท ga ยท ga โ€” character info under cursor.
[missing screenshot prefix.g/frame_05.color.svg โ€” run python content/render_screenshots.py]

Watch

See also: The z Family, The [ and ] Family, The Ctrl-W Family, Complete Key Reference