什么:q1在Vim中做什么?

scu*_*bbo 14 vim

我刚刚注意到,输入:q1关闭了我目前打开的文件(我通过拼写找到了这个:q!)

基于诸如2dd(删除两行)或2j(向下移动两行)之类的命令,我本来期望:2q"退出两个文件"(但是,如果我打开两个文件vi -O testfile1 testfile2,:2q 关闭其中一个 - 同样如此:q2).

:q简单丢弃后的数字是多少?或者它是否有一些我无法确定的效果?

而且,更一般地说 - 我怎么能为自己回答这个问题?我检查usr_21.txt| Go away and come back了Vim帮助,但没有发现这种行为.我甚至检查了这个着名的问题,但没有人提到过这个问题.

Sub*_*ash 14

q带数字的命令将关闭该位置的给定分割.

:q<split position>:<split position>q将关闭该位置的分割.

让我们说你的vim窗口布局如下:

-------------------------------------------------
|               |               |               |
-------------------------------------------------
|               |               |               |
|               |               |               |
|    Split 1    |    Split 2    |     Split 3   |
|               |               |               |
-------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

如果运行q1命令,它将关闭第一次拆分.q2将关闭第二次拆分,反之亦然.

quit命令中拆分位置的顺序无关紧要.:2q:q2将关闭第二次分裂.

如果传递给命令的分割位置大于当前分割的数量,则它将简单地关闭最后一个分割.

例如,如果q100在上面的窗口设置中运行,只有3个拆分,它将关闭最后一个拆分(拆分3).

这是vim文档中列出的内容.您可以通过键入找到文档,:help :close然后向上滚动以查找该Closing a window部分.

If [count] is greater than the last window number the last
window will be closed:
¦ ¦ :1quit  " quit the first window
¦ ¦ :$quit  " quit the last window
¦ ¦ :9quit  " quit the last window
     " if there are fewer than 9 windows opened
¦ ¦ :-quit  " quit the previous window
¦ ¦ :+quit  " quit the next window
¦ ¦ :+2quit " quit the second next window
Run Code Online (Sandbox Code Playgroud)