【问题标题】:What are the vim commands that start with g?以g开头的vim命令有哪些?
【发布时间】:2017-07-14 01:31:34
【问题描述】:

g 是几个命令的前缀。例如goto 移动光标,还 gqip 格式化段落。所有以g为前缀的命令的参考在哪里?

【问题讨论】:

  • 在 Vim 中,输入::help g
  • 它们就是“以 g 开头的命令”。
  • @romainl 所以这些命令中的“g”并不意味着特定的东西,例如它的所有命令组合中的“d”代表删除的行为。
  • @SamuelMyself, d 是一名操作员。每当它与一个动作结合使用时,它就充当自己:“在这些括号之间删除”、“从这里删除到 EOL”等。另一方面,g 什么都不是:不是运算符,不是命令,不是动议。这只是 Vim 的创建者几十年来一直用作新命令的垃圾箱的一个空槽。如果你能找到一些对你有好处的助记技巧,但这些命令真的无处不在。
  • @romainl 谢谢,正是我需要知道的 :)

标签: vim


【解决方案1】:

Vim 的文档是http://vimdoc.sourceforge.net/。如果您查看 HTML 文档,您会发现 |reference_toc| More detailed information for all commands,其中包括 |index.txt| alphabetical index of all commands,由于一个名为 index.txt 并链接为 index.html 的 doc 文件的不幸怪癖,它实际上并没有导致到你期望它引导的地方。

长话短说,http://vimdoc.sourceforge.net/htmldoc/vimindex.html#g 是您要查找的文档(“以 'g' 开头的命令”)。

或者,在 Vim 中键入 :help *g*

(抱歉 merlin2011,但您的列表有些不完整...)


应用了一些重新格式化:

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

【讨论】:

  • OP 要求提供参考位置,而不是完整参考;这就是为什么我没有复制整个输出。
  • gU{motion} 2 make Nmove text uppercase 到底是什么意思?什么是 Nmove?
  • @jaaq 将函数(“转大写”)与移动(“到词尾”、“到行尾”、“下两段”)结合起来是 Vim 的基本原理)。试试gU5e,看看 Vim 把从光标到第 5 个单词结尾的所有内容都变成大写。
  • @DevSolar 这些命令中的“g”并不意味着特定的东西,例如其命令的所有组合中的“d”代表删除的行为
  • @SamuelMyself:有点。 'g' 和 'z' 是“转义”到 didn't fit 的“额外”命令。 ;-)
【解决方案2】:

打开vim。输入: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

为了便于阅读,上面的列表已被截断。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2016-03-18
    • 2018-07-27
    相关资源
    最近更新 更多