I use CTRL-W c
to close current window.
I expected that 5 CTRL-W c
close 5 windows in row, but it's not. Now I just type CTRL-W c
5 times.
What is correct way to do it and why it don't work as I expected?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityFirst, giving a count to the command doesn't work as you expected because the doc (:h CTRL-W_c
) says:
Without {count}: Close the current window. If {count} is
given close the {count} window.
Now if you want to create a mapping calling <C-w>c
N times you could add this to your vimrc:
nnoremap <F1> :<C-u>for i in range(v:count1) \| close \| endfor<CR>
Replace <F1>
by the key you want to use in your mapping. What is line does is the following:
: Go to command line mode
<C-u> Remove the range automatically added to the command line
for i in range(v:count1) Create a loop from 0 to the count you gave to the mapping (or 1 if you didn't gave a count)
close Close the current window
endfor End of the loop
<CR> Validate the command
Now you can press <F1>
to close the current window and 4<F1>
to close the current window and the 3 next current windows.
You can read the following related help topics:
:h c_CTRL-U
instead... :h CTRL-U
is about page up in normal mode...
:only
or<c-w>o
. See:h :only
ZZ
and any of the other quit/exit mechanisms close a window (unless it’s the last window, and then they quit)