44

g is a prefix to several commands. e.g. goto to move the cursor, but also gqip to format a paragraph. Where is the reference for all commands that are prefixed with g?

5
  • 5
    In Vim, type: :help g
    – mkrieger1
    Jul 13, 2017 at 17:10
  • 1
    They are exactly that, "commands that start with g".
    – romainl
    Jul 13, 2017 at 17:46
  • @romainl So does 'g' in these commands does not mean something specific, such as 'd' in all the combination of its commands represents the act of deletion. Dec 20, 2020 at 15:06
  • 6
    @SamuelMyself, d is an operator. Whenever it is used in combination with a motion it acts as itself: "delete between these parentheses", "delete from here to EOL", etc. On the other hand, g is nothing: not an operator, not a command, not a motion. It was just an empty slot that Vim's creator has been using for decades as a dumpster for new commands. If you can find a mnemonic trick for some of them good for you but those commands are really all over the place.
    – romainl
    Dec 20, 2020 at 20:39
  • 1
    @romainl thanks, exactly what I needed t know :) Dec 21, 2020 at 7:48

2 Answers 2

43

Vim's documentation is http://vimdoc.sourceforge.net/. If you go for the HTML docs, you will find |reference_toc| More detailed information for all commands, which includes |index.txt| alphabetical index of all commands, which -- due to an unfortunate quirk with the doc file named index.txt and linked as index.html -- doesn't actually lead to where you would expect it to lead.

Long story short, http://vimdoc.sourceforge.net/htmldoc/vimindex.html#g is the documentation you are looking for ("Commands starting with 'g'").

Alternatively, type :help *g* in Vim.

(Sorry merlin2011 but your list is somewhat incomplete...)


Some reformatting applied:

2.4 Commands starting with 'g'

 char        note action in Normal mode
------------------------------------------------------------------
g CTRL-A          only when compiled with MEM_PROFILE
                  defined: dump a memory profile
g CTRL-G          show information about current cursor
                  position
g CTRL-H          start Select block mode
g CTRL-]          |:tjump| to the tag under the cursor
g#             1  like "#", but without using "\<" and "\>"
g$             1  when 'wrap' off go to rightmost character of
                  the current line that is on the screen;
                  when 'wrap' on go to the rightmost character
                  of the current screen line
g&             2  repeat last ":s" on all lines
g'{mark}       1  like |'| but without changing the jumplist
g`{mark}       1  like |`| but without changing the jumplist
g*             1  like "*", but without using "\<" and "\>"
g0             1  when 'wrap' off go to leftmost character of
                  the current line that is on the screen;
                  when 'wrap' on go to the leftmost character
                  of the current screen line
g8                print hex value of bytes used in UTF-8
                  character under the cursor
g<                display previous command output
g?             2  Rot13 encoding operator
g??            2  Rot13 encode current line
g?g?           2  Rot13 encode current line
gD             1  go to definition of word under the cursor
                  in current file
gE             1  go backwards to the end of the previous
                  WORD
gH                start Select line mode
gI             2  like "I", but always start in column 1
gJ             2  join lines without inserting space
["x]gP         2  put the text [from register x] before the
                  cursor N times, leave the cursor after it
gQ                switch to "Ex" mode with Vim editing
gR             2  enter Virtual Replace mode
gU{motion}     2  make Nmove text uppercase
gV                don't reselect the previous Visual area
                  when executing a mapping or menu in Select
                  mode
g]                :tselect on the tag under the cursor
g^             1  when 'wrap' off go to leftmost non-white
                  character of the current line that is on
                  the screen; when 'wrap' on go to the
                  leftmost non-white character of the current
                  screen line
ga                print ascii value of character under the
                  cursor
gd             1  go to definition of word under the cursor
                  in current function
ge             1  go backwards to the end of the previous
                  word
gf                start editing the file whose name is under
                  the cursor
gF                start editing the file whose name is under
                  the cursor and jump to the line number
                  following the filename.
gg             1  cursor to line N, default first line
gh                start Select mode
gi             2  like "i", but first move to the |'^| mark
gj             1  like "j", but when 'wrap' on go N screen
                  lines down
gk             1  like "k", but when 'wrap' on go N screen
                  lines up
gm             1  go to character at middle of the screenline
go             1  cursor to byte N in the buffer
["x]gp         2  put the text [from register x] after the
                  cursor N times, leave the cursor after it
gq{motion}     2  format Nmove text
gr{char}       2  virtual replace N chars with {char}
gs                go to sleep for N seconds (default 1)
gu{motion}     2  make Nmove text lowercase
gv                reselect the previous Visual area
gw{motion}     2  format Nmove text and keep cursor
gx                execute application for file name under the
                  cursor (only with |netrw| plugin)
g@{motion}        call 'operatorfunc'
g~{motion}     2  swap case for Nmove text
g<Down>        1  same as "gj"
g<End>         1  same as "g$"
g<Home>        1  same as "g0"
g<LeftMouse>      same as <C-LeftMouse>
g<MiddleMouse>    same as <C-MiddleMouse>
g<RightMouse>     same as <C-RightMouse>
g<Up>          1  same as "gk"

note: 1 = cursor movement command; 2 = can be undone/redone
5
  • 2
    The OP asked for a reference location, not the full reference; That's why i didn't copy the entire output.
    – merlin2011
    Jul 13, 2017 at 17:32
  • 1
    What does gU{motion} 2 make Nmove text uppercase mean exactly? What is Nmove?
    – jaaq
    May 16, 2019 at 17:09
  • 1
    @jaaq It is a basic principle of Vim to combine a function ("turn uppercase") with a movement ("to end of word", "to end of line", "next two paragraphs"). Try gU5e, and see Vim turning everything from the cursor to the end of the 5th word into uppercase.
    – DevSolar
    May 16, 2019 at 17:14
  • 1
    @DevSolar does 'g' in these commands not mean something specific, such as 'd' in all the combination of its commands represents the act of deletion Dec 20, 2020 at 15:08
  • 3
    @SamuelMyself: Kind of. 'g' and 'z' are "escapes" into "extra" commands that didn't fit anymore. ;-)
    – DevSolar
    Dec 20, 2020 at 20:43
11

Open vim. Type :help g.

2.4 Commands starting with 'g'                                          g

tag             char          note action in Normal mode
------------------------------------------------------------------------------
g_CTRL-A        g CTRL-A           only when compiled with MEM_PROFILE
                                   defined: dump a memory profile
g_CTRL-G        g CTRL-G           show information about current cursor
                                   position
g_CTRL-H        g CTRL-H           start Select block mode
g_CTRL-]        g CTRL-]           :tjump to the tag under the cursor
g#              g#              1  like "#", but without using "\<" and "\>"
g$              g$              1  when 'wrap' off go to rightmost character of
                                   the current line that is on the screen;
                                   when 'wrap' on go to the rightmost character
                                   of the current screen line
g&              g&              2  repeat last ":s" on all lines
g'              g'{mark}        1  like ' but without changing the jumplist
g`              g`{mark}        1  like ` but without changing the jumplist
gstar           g*              1  like "*", but without using "\<" and "\>"
g+              g+                 go to newer text state N times
g,              g,              1  go to N newer position in change list
g-              g-                 go to older text state N times
g0              g0              1  when 'wrap' off go to leftmost character of
                                   the current line that is on the screen;
                                   when 'wrap' on go to the leftmost character
                                   of the current screen line
g8              g8                 print hex value of bytes used in UTF-8
                                   character under the cursor
g;              g;              1  go to N older position in change list
g<              g<                 display previous command output

The list above has been truncated for readability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.