The g Family
30+ commands hide behind the g prefix.
g is a meta prefix: it gates a second, hidden keyboard of commands. From gd (go to definition) and gf (go to file) to gq (reformat) and gv (re-select), the g family covers everything that didn't fit elsewhere.
The g Family
The g prefix is Vim's miscellaneous drawer โ and it's huge. Roughly thirty commands live behind it. The unifying theme is "this didn't fit on a one-key shortcut, so it got the g prefix." Worth a flat reference table.
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 |
| gi | Insert at last Insert 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 | Visual-select next search match |
| gN | Visual-select previous search match |
| gp / gP | Like p/P, but cursor lands AFTER pasted text |
| gt / gT | Next / previous tab |
| gr{c} | Replace (virtual) โ see `transform.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.
Watch
- ๐บ #0249 ga ASCII Value (not yet published)
- ๐บ #0285 g@ Apply Operator (not yet published)
See also: The {key:z} Family, The {key:[} and {key:]} Family, The {key:Ctrl-W} Family, Complete Key Reference