Hot answers tagged

110 votes

Swap the position of two windows

To swap the two parts of a split window simply do: <C-w> <C-r>
modesto's user avatar
  • 1,225
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 ...
statox's user avatar
  • 49.4k
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 ...
JigglyNaga's user avatar
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 ...
Tom Hale's user avatar
  • 2,601
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 ...
Chan Youn's user avatar
  • 283
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.
romainl's user avatar
  • 39.3k
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 ...
Mike Holt's user avatar
  • 278
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. ...
Tommy A's user avatar
  • 6,710
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 '...
ELLIOTTCABLE's user avatar
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 ...
romainl's user avatar
  • 39.3k
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 - ...
meain's user avatar
  • 247
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 ...
galian's user avatar
  • 191
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 ...
statox's user avatar
  • 49.4k
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 ....
qeatzy's user avatar
  • 940
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 ...
alexhg's user avatar
  • 181
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 ...
DJMcMayhem's user avatar
  • 17.4k
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}. ...
DJMcMayhem's user avatar
  • 17.4k
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", ...
statox's user avatar
  • 49.4k
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 [++...
dedowsdi's user avatar
  • 6,188
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 ...
Matt's user avatar
  • 20.4k
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 ...
Ralf's user avatar
  • 9,097
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 ...
statox's user avatar
  • 49.4k
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: ...
muru's user avatar
  • 24.7k
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 ...
statox's user avatar
  • 49.4k
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] ...
Christian Brabandt's user avatar
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 ...
statox's user avatar
  • 49.4k
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 ...
statox's user avatar
  • 49.4k
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 ...
Shamaoke's user avatar
  • 221
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 ...
Geremia's user avatar
  • 956
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 "...
padawin's user avatar
  • 1,323

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