How can I create new window with new buffer in vim, vertical with shortcuts?
(Similar to Ctrl-w n, but vertically.)
-
1Inverse of the action? Or reverse of the window split whilst keeping the buffer? Or split in the opposite direction? Or split in the perpendicular direction?JdeBP– JdeBP2020-01-02 09:20:16 +00:00Commented Jan 2, 2020 at 9:20
1 Answer
The Ctrl+Wn shortcut is the same as the newcommand. There is also a vnew command that works exactly as new, but splits vertically. To use it, type Esc:vnewEnter.
You could also remap e.g. Ctrl+Wv from doing the equivalent of vsplit (the default) to vnew using something like
noremap <C-w>v <esc>:vnew<cr>
in your ~/.vimrc file.
Note: When the below answer was written, the question asked for the "contrary" action to Ctrl+Wn. I interpreted this as "the opposite of splitting and creating a new window, i.e. closing a split window".
The q command closes the current buffer (this would be entered as Esc:qEnter). If that is done in one of the buffers that you get from splitting, you will get back to an editor window containing only a single buffer, reversing the effect of Ctrl+Wn.
You may also use Ctrl+Wq for doing this.
-
Thanks and sorry for my english!!user377583– user3775832020-01-03 00:26:37 +00:00Commented Jan 3, 2020 at 0:26
-
But you have mapped "ctrl-w v" which is used to divide the screen vertically but WITHOUT new buffer ... Of DEFAULT, there is no shortcut for ":vnew"?user377583– user3775832020-01-03 00:27:04 +00:00Commented Jan 3, 2020 at 0:27
-
For config file using lua:
vim.keymap.set('n', '<C-w>v', '<esc>:vnew<cr>', { noremap = true})Fanchen Bao– Fanchen Bao2024-01-18 05:21:05 +00:00Commented Jan 18, 2024 at 5:21 -
@FanchenBao I suppose that would be for NeoVim, not Vim, right?2024-01-18 08:37:33 +00:00Commented Jan 18, 2024 at 8:37
-
Yes, for NeoVim. I should've specified it in the comment.Fanchen Bao– Fanchen Bao2024-01-18 20:32:20 +00:00Commented Jan 18, 2024 at 20:32