Hot answers tagged

162

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 height (ex. 50<C-w>_) Ctrl+W |: set width (ex. 50<C-w>|) Ctrl+W =: equalize width and height of all windows See also: :help CTRL-W


65

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 respectively. Additionally, I would recommend to also read :h window-move-cursor for moving around different splits with ease.


44

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 decreasing height by N characters. :resize N - resize a horizontal split, setting height to N characters. :vertical resize N - resize a vertical split, setting width ...


41

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 visible in any window on any tab), you'll have to add a function to your vimrc. Some people have posted possible functions to here and here I'm not sure exactly ...


39

You can use the option -o to open the files in horizontal splits or -O to open vertical splits. The following commands open a window for each file specified: vim -o *.cpp vim -O foo bar baz You can tell Vim the maximum number of windows to open by putting an integer after o or O options, the following example will open at most two windows no matter how ...


33

To swap the two parts of a split window simply do: <C-w> <C-r>


32

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 just use a pipe-like character. Tmux uses │ (U+2502) by default while Vim uses | (U+007C). If you want the same separator in Vim, you can simply use the same ...


30

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 line and drag to resize the window exactly where you want, without a lot of guess work using the ctrl-w plus,minus,less,greater combinations. In terminal versions,...


27

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 windows are closed. See also: How to convert all windows into horizontal, vertical or tab splits? at Vim SE How to cancel splitted windows? at stackoverflow SE Is ...


23

You can just 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 default <C-e> mapping (scroll down). Vim already uses every key on the keyboard, and the only way to prevent this is using the leader key, which ...


22

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 time you open Vim): :autocmd VimResized * wincmd = Here are the docs for the VimResized autocmd.


22

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 is no next window, exchange with previous window. With count: Exchange current window with Nth window (first window ...


19

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 the full set of commands to quit multiple windows at once.


19

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 of 'scrollbind' can be modified by the 'scrollopt' option. :help scrollopt reveals that you want to say :set scrollopt+=hor to enable horizontal scrolling. ...


17

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 normal hjkl cursor movement keys, or the arrow keys). You can then :edit (etc.) a different file in each window. Full documentation is at :help windows.txt.


17

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:last_terminal_job_id = b:terminal_job_id augroup END Which will save the the job id of the last created terminal into the g:last_terminal_job_id variable. Then you can ...


16

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 to split vertically. :[N]ba[ll] [N] :[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in the buffer list. :vert[ical] {cmd} ...


15

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, this would look something like: vnoremap <F5> y<c-w>wp<c-w>pgv "explanation: xnoremap <F5> Remap F5 in visual/select ...


13

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.


13

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.


13

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 buffer. A viewport is synonymous with a window. A tab page contains one or more windows. You can see what windows are in which tab with :tabs. A split is where ...


12

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 set and the file can be written. And you can use :enew! to discard unsaved changes in the current buffer.


11

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 specified. However, it seems like Vim does not provide a mapping for :vnew which creates a new blank vertical split. It's easy to create this mapping yourself. For instance: ...


10

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 before the switch (i.e. if before the switch the focused window is on the left, after the switch it will be on the left). <c-w>x will switch the windows and ...


10

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 new split with the same buffer as the current split. The :tab command can run many window-related commands, changing them to use a tab instead. Combining these ...


9

I don't think there's any way to do this, however a better approach in this case would be to leverage vim's folding to fold away part of the code between the structures you're interested in and that can make it a lot more easy for you to visually see the matching brackets. You can also use % to jump between the start & end parenthesis too to get a fair ...


9

I don't know if it is the best way to do what you want, but you can accomplish this only with window movements by doing (start from the rightmost window b3): 1 - CTRL-W+K - You'll have: ---------------- | b3 | |------|-------| |b1 | b2 | ---------------- 2 - Go to b1 with CTRL-W+j 3 - CTRL-W+H to move b1 to the left. You should have the ...


9

'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.


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