我刚刚注意到输入 :q1
关闭我当前打开的文件(我通过输入 :q!
找到了这个)
基于 2dd
之类的命令(删除两行)或 2j
(下移两行),我本来以为 :2q
“退出两个文件”(尽管,如果我用 vi -O testfile1 testfile2
打开两个文件, :2q
只会关闭其中一个 - :q2
也是如此)。
是:q
后面的数字简单地丢弃?或者它是否有一些我无法确定的影响?
而且,更一般地说 - 我怎么能自己回答这个问题?我查了 usr_21.txt| Go away and come back
在 Vim 帮助中,但未发现有关此行为的任何信息。我什至检查了famous question ,但没有人提及此事。
最佳答案
q
带有数字的命令关闭该位置的给定拆分。:q<split position>
或 :<split position>q
将关闭该位置的拆分。
假设您的 vim 窗口布局如下:
-------------------------------------------------
| | | |
-------------------------------------------------
| | | |
| | | |
| Split 1 | Split 2 | Split 3 |
| | | |
-------------------------------------------------
如果您运行
q1
命令它将关闭第一个拆分。 q2
将关闭第二个拆分,反之亦然。退出命令中拆分位置的顺序无关紧要。
: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
关于vim - :q1 do in Vim? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48757147/