I just noticed that entering :q1
closes the file I currently have open (I found this by typo-ing :q!
)
Based on commands like 2dd
(
The q
command with number closes the given split in that position.
:q<split position>
or :<split position>q
will close the split in that position.
Lets say your vim window layout is as follows:
-------------------------------------------------
| | | |
-------------------------------------------------
| | | |
| | | |
| Split 1 | Split 2 | Split 3 |
| | | |
-------------------------------------------------
If you run q1
command it will close the first split. q2
will close the second split and vice versa.
The order of split position in the quit command does not matter. :2q
or :q2
will close the second split.
If the split position you pass to the command is greater than the number of current splits, it will simply close the last split.
For example, if you run the q100
on the above window setup where there are only 3 splits, it will close the last split (Split 3).
This is whats listed in the vim documentation. You can find the documentation by typing :help :close
then scroll up to find the Closing a window
section.
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