110
votes
Swap the position of two windows
To swap the two parts of a split window simply do: <C-w> <C-r>
36
votes
Accepted
How do I open a new buffer without opening it in a split?
You can use :enew. See :h :enew:
Edit a new, unnamed buffer. This fails when changes
have been made to the current buffer, unless 'hidden'
is set or 'autowriteall' is ...
34
votes
Swap the position of two windows
CTRL-W x exchange current window with window N
(default: next window)
(index.txt section 2.2, "Window commands")
If A is the current window, then the next will be B, so ...
18
votes
What is the difference between a tab, viewport, window, split and buffer?
A buffer is the in-memory text of a file. It may differ from the saved version of the file.
A window is a view of a buffer. You can have two (or more) windows editing different parts of the same ...
15
votes
Swap the position of two windows
Another alternative to swapping windows or swapping the buffers, is to mark positions (using uppercase marks) in your files and open up those marks in the windows of your choosing.
For example if I ...
15
votes
Accepted
How should the option 'switchbuf' work?
'switchbuf' is only honored by quickfix commands (like :cc) and buffer-splitting commands (like :sb).
It doesn't affect :buffer and other "regular" buffer-related commands.
14
votes
Accepted
How to do :Sex but with a vertical split?
What you're looking for is :Vexplore.
From your question, it sounds like you started off knowing only about :Sexplore and understandably thought that that was the basic command for bringing up the ...
12
votes
Accepted
Is it possible to obtain the displayable area, width and height of current buffer in Vim?
These are the different ways (that I know of) to get dimensional information from Vim.
Vim
&columns and &lines will give you the total width and height of the screen Vim is displayed in. ...
12
votes
Accepted
How to lock a window height / width?
If you're like me, and came across this question when hoping to make a particular window have a fixed width (or height) without disabling 'equalalways' and avoiding Ctrl-W=, you should be aware of '...
11
votes
Accepted
how to use Netrw Directory Listing in VIM split window without exiting it when a file has been read
There is a dedicated command for opening a netrw listing in a vertical split:
:Vex[plore]
There is a dedicated command for going back to the latest netrw listing:
:Rex[plore]
Netrw comes with a ...
9
votes
Is it possible to have the output of a :! command in a split rather than the whole window?
You can use this command :
:new | 0read ! command
This will open up a new split and puts the output of the command in this split (though not in the currently active split as you mentioned).
new - ...
9
votes
How do I change the current split's width and height?
Resize splits more quickly
You can use the :resize command or its shortcut :res to change the height of the window. To change the height to 60 rows, use:
:resize 60
You can also change the height in ...
9
votes
Is it possible to simultaneously edit one file in two views?
I think you need to read :h windows-intro which explains the concepts of buffer, window and tab, summarized like this:
Summary:
A buffer is the in-memory text of a file.
A window is a viewport ...
8
votes
How do I change the current split's width and height?
Seems no one mentioned z{nr}<CR>.
If you :h ^w_, then will see z{nr}<CR> just below it, which have same effect as CTRL-W_.
If you do not need z= for spell check, and added below to ....
8
votes
Can I open a new vim split from an existing buffer?
:(v)split <name_of_buffer> or :(v)split #<buffer_number>
This answer shows a shorter way to @user72's answer above and @zepp.lee's comment.
For example, you can open buffer 2 in a ...
8
votes
Accepted
Spread already open files into split view
Here are a bunch of helpful commands for you:
To open every buffer in a horizontal split:
:sball
To open every buffer in a vertical split:
:vert sball
You can do the same thing with tabs, e.g, to ...
8
votes
Accepted
How can I open a split at whose height is a percentage of the main window?
The winheight function will return the height of window n. From :h winheight():
winheight({nr}) *winheight()*
The result is a Number, which is the height of window {nr}.
...
8
votes
How to lock a window height / width?
If you read the doc for the command you use you will see :h CTRL-W_S:
Reduces the current window height to create room (and others, if the 'equalalways' option is set, 'eadirection' isn't "hor", ...
8
votes
Accepted
Can I :split and go directly to a line?
You are so close:
:split +50 fnord.txt
All commands in vim that create new buffer has prototype:
cmd [++opt] [+cmd] [file]
All commands in vim that write buffer to your disk has prototype:
cmd [++...
8
votes
How to open files in vertical splits by default?
:split, :new and such are "horizontal" commands. But they all have "vertical" counterparts: :vsplit, :vnew etc. Take a habit to choose the right ones.
Also, you're not allowed to redefine Vim builtin ...
8
votes
Accepted
Open multiple files in custom split layout
You could try it like this:
vim -c "lefta vsplit file2.txt|split file1.txt" file3.txt
With the option -c you can specify commands that should be executed after the first file was loaded.
So ...
7
votes
Accepted
How to auto save file when moving between split?
What you are looking for is a way to trigger the autocommand each time you leave a buffer to another location.
Conveniently the autocommand event BufLeave was made precisely for that, so you just ...
7
votes
Accepted
Problem when assigning a keybinding to open the output of a shell command in vim
To open the output of a command in a new window:
:new +0r!ls
Note the syntax of new:
:[N]new [++opt] [+cmd] :new
And for +cmd:
...
7
votes
How can I work with splits in Vim without Ctrl-W?
To deal with splits I use the submode-plugin which is actually pretty convenient: It allows you to create a new mode ("mode" like in normal mode, visual mode, insert mode, etc...) where you define new ...
7
votes
How to open a file from active buffer into a split window?
You can do :2sbN or :sbN 2 to split the window and go to the 2 buffer. To split the window vertically, you can use :vert sbN 3 to go to buffer 3.
An alternative solution is to use the :sp [+cmd] ...
7
votes
Accepted
Working with error lists while compiling
You should look at :h quickfix.txt.
Vim has a special mode to speedup the edit-compile-edit cycle. This is
inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
The idea ...
7
votes
Accepted
How to change the location of a new vertical split?
You should use:
:botright vsp myFile.txt
See :h botright:
Execute {cmd}. If it contains a command that splits a window,
it will appear at the bottom and occupy the full width of the
...
7
votes
Accepted
Carets in status line
This is the standard behaviour of Vim. If StatusLine and StatusLineNC have the same highlighting, the program will use the caret character (^) in the status line of the current window (in order to ...
7
votes
Accepted
Open ctrl+] in a new split?
This will do it:
CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]*
CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a
tag and jump to it in the new upper ...
7
votes
Accepted
How can I focus on one vimsplit fullscreen?
When focused on it, run:
:tabe %
To open a new tab with the same file. You can navigate tabs with gT and gt among other, if you want to go back to your split.
Once you are done with it, on the "...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
split × 181vim-windows × 36
buffers × 21
key-bindings × 17
neovim × 17
vimrc × 11
multiple-files × 11
command-line × 9
tabbed-user-interface × 9
vimscript × 8
netrw × 7
vimdiff × 6
scrolling × 5
gvim × 4
plugin-nerdtree × 4
tmux × 4
window-management × 4
syntax-highlighting × 3
terminal × 3
statusline × 3
macos × 3
navigation × 3
autocmd × 2
cursor-movement × 2
microsoft-windows × 2