Hot answers tagged

309 votes
Accepted

How do I change the current split's width and height?

There are several window commands that allow you to do this: Ctrl+W +/-: increase/decrease height (ex. 20<C-w>+) Ctrl+W >/<: increase/decrease width (ex. 30<C-w><) Ctrl+W _: set ...
  • 14.1k
106 votes
Accepted

Is it possible to split Vim window to view multiple files at once?

Yes, vim has the ability to split both horizontally using :split and vertically using :vsplit which both work just like :edit for opening a file, except they open it in a horizontal / vertical split ...
  • 5,290
100 votes

Swap the position of two windows

To swap the two parts of a split window simply do: <C-w> <C-r>
  • 1,109
85 votes
Accepted

How to open multiple files in split mode?

You can use the option -o to open the files in horizontal splits or -O (letter "O") to open vertical splits. The following commands open a window for each file specified: vim -o *.cpp vim -O ...
  • 4,592
77 votes

How do I change the current split's width and height?

You can also use the resize commands: :resize [+-]N - resize a horizontal split, increasing or decreasing height by N characters. :vertical resize [+-]N - resize a vertical split, increasing or ...
  • 24.1k
72 votes
Accepted

Close all split files, except the one currently focused?

If you want to close all windows(splits) except the current one: :only If you want to close all tabs except the current one: :tabonly If you want to delete all hidden buffers (files open but not ...
  • 2,878
54 votes

How do I change the current split's width and height?

This is one of the few reasons I like to use vim's mouse mode. If you use the GUI version, or your terminal supports sending drag events (such as xterm or rxvt-unicode) you can click on the split ...
  • 8,172
51 votes

Close all split files, except the one currently focused?

Press Ctrl+w,o to quickly close all split windows, but current one. Alternatively use the command: :on (:only). :on[ly][!] Make the current window the only one on the screen. All other ...
  • 17.2k
42 votes
Accepted

Can the split separator in vim be less than a full column wide?

You are wrong about tmux. Like every terminal-based program — including Vim — it only draws stuff inside cells. This means that Vim and tmux both use the same method to draw vertical borders: they ...
  • 34.1k
39 votes
Accepted

How can I work with splits in Vim without Ctrl-W?

You can remap <C-w> to another combination, for example: :nnoremap <C-e> <C-w> You can now use <C-e> and it will act as if you've pressed <C-w>. This will overwrite the ...
36 votes

Is it possible to split Vim window to view multiple files at once?

Yes, there are the :split (split into two windows, top half and bottom half) and :vsplit (left and right) commands. You can then use Ctrl-W direction to switch windows (where direction is one of the ...
  • 1,865
35 votes
Accepted

Make panes resize when host window is resized

To go along with @janos's answer, you can set an autocmd to automatically press those keys when the window is resized (put this in your .vimrc without the leading colon if you want it to apply every ...
  • 14.1k
34 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 ...
  • 47.3k
33 votes
Accepted

In Vimdiff, how do I switch the left and right panes?

You can use Ctrlw-x. From :he CTRL-W_x: CTRL-W x CTRL-W_x CTRL-W_CTRL-X CTRL-W CTRL-X Without count: Exchange current window with next one. If there ...
  • 24.1k
30 votes
Accepted

How can I get both splits to scroll left or right at the same time?

To scroll two windows together in vim, need to run :set scrollbind in each of them. As you noted, by default, this only binds vertical scrolling. In the docs for scrollbind, it mentions: The behavior ...
  • 2,878
29 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 ...
27 votes

Is it possible to split Vim window to view multiple files at once?

You can either split vim windows by opening multiple files using -o, -O, -o2 parameters. Or if you're already editing multiple files in one window, you can use :ba to split horizontally or :vert ba ...
  • 17.2k
24 votes

How can I work with splits in Vim without Ctrl-W?

I actually use :wincmd more often than Ctrl+W because I find it easier to type the abbreviated :winc. For example, the equivalent to Ctrl+W L is :winc l.
23 votes
Accepted

How to exit Vim from split mode?

Use the command :qall!, :qa! for short, or its safer alternative :qall that prevent to discard modified buffers. To save all buffers before quitting use the command :wqall. See :help window-exit for ...
  • 4,592
18 votes

Send text from one split window to another

Neovim terminal buffers always have an associated job id, so one way is to use the job control API to send the text. Add this to your vimrc: augroup Terminal au! au TermOpen * let g:...
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 ...
  • 2,361
17 votes
Accepted

Send text from one split window to another

Basically when you have text selected, you want to remap a key sequence to copy, switch to terminal, paste, and then possibly switch windows back and reselect the text. If you have two splits open, ...
  • 2,878
17 votes
Accepted

Vertical equivalent of "control+w n"?

From :help vnew: Like |:new|, but split vertically. If 'equalalways' is set and 'eadirection' isn't "ver" the windows will be spread out horizontally, unless a width was ...
  • 6,076
16 votes

Make panes resize when host window is resized

Ctrlw= will resize the split panes to become equal. But I don't know how to make them equal automatically, triggered when the window is resized.
  • 2,708
14 votes

In Vimdiff, how do I switch the left and right panes?

As you would switch any other window, <c-w>x or <c-w>r are two options. Having only two windows opended <c-w>k will switch them and leave the cursor in the window where it was ...
  • 4,592
14 votes

Is it possible to split Vim window to view multiple files at once?

You can use :split or :vsplit for horizontal and vertical splits respectively. Provide the path to the file you want to open to open a specific file. Or just type the command to open a copy if the ...
  • 593
13 votes

How to undo/revert making current window the only window (":only" / "<C-W> o")?

Another option could be to open your current window in a new tab, then simply close the tab when you're done. The :split (or :sp for short) command, without an argument, has the effect of opening a ...
  • 7,360
13 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 ...
  • 253

Only top scored, non community-wiki answers of a minimum length are eligible