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
62 votes
Accepted

What are the new "popup windows" in Vim 8.2?

Background: I have a plugin for navigating sections in markup documents and wanted to show the section hierarchy in a popup. I distilled what I learned while implementing this down to the following ...
B Layer's user avatar
  • 19.6k
36 votes
Accepted

How to apply a setting in all open tabs and windows?

Yes, there is! You can accomplish this with :tabdo and :windo. For your case specifically: :tabdo windo set number See :help :tabdo and :help :windo for more information.
Tumbler41's user avatar
  • 7,706
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
27 votes
Accepted

Get the current window/buffer/tabpage in Vimscript

Well… it's just as simple in vimscript. Current window Python: current_win = vim.current.window Vimscript: let current_win = winnr() Current buffer Python: current_buff = vim.current.buffer ...
romainl's user avatar
  • 39.3k
25 votes

How to switch between buffer and terminal

A better way which I use (and love these days) to jump between terminal (interactive mode with all alias and path set) and vim is using CTRL+Z in normal mode. Work on terminal, and when done type fg ...
avimehenwal's user avatar
23 votes
Accepted

How to make the two windows equal width when comparing files?

You can equalize the size of windows with <c-w>=.
ChoiZ's user avatar
  • 348
22 votes
Accepted

How to switch between buffer and terminal

From :h terminal-typing CTRL-W can be used to navigate between windows and other CTRL-W commands, e.g.: CTRL-W CTRL-W move focus to the next window CTRL-W : enter an Ex command
Tuyen Pham's user avatar
  • 1,276
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
18 votes
Accepted

What is a scratch window?

It is probably a scratch buffer, which can be named. From the help: scratch Contains text that can be discarded at any time. It is kept when closing the window, it must be deleted explicitly. ...
wbogacz's user avatar
  • 315
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
14 votes

How to "full screen" browse Vim help?

You can move the help screen to its own tab with ctrl+w T (note the T is upper case). Then you can switch between the tabs with gt.
wisbucky's user avatar
  • 920
13 votes
Accepted

How do I stop my window from moving when using vsplit?

This happens because when vertical splitting the window, vim needs to add a vertical scrollbar, which causes vim to recalculate the visual size and eventually makes vim jump to a different screen ...
Christian Brabandt's user avatar
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

How can I open a buffer in a new tab leaving the current window and buffer intact?

:tab split will create a new tab displaying the current buffer, since :tab modifies any command that would normally create a split to instead create a tab page. If you want to override <C-w>T ...
jamessan's user avatar
  • 10.9k
10 votes

What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?

This is the first result show up on google search about 'Vim event order'. So, i think it's worth providing the actual answer. Using the command from @nobe4 answer, this is the result: Opening a new ...
C. Martins's user avatar
10 votes
Accepted

How to preview the result of markdown file edited in vim?

While I mostly agree with @romainl comment (markdown was made to be explicit enough not to need a preview) you can do this in different ways: [OSX / Unix] The instant-markdown plugin is a solution. ...
statox's user avatar
  • 49.4k
10 votes

How to switch between buffer and terminal

After opening a terminal window within vim with :te[rminal] and switching to insert mode (needed to type in the terminal), all keys are sent to the terminal, so esc doesn't switch back to normal mode (...
mrtnmgs's user avatar
  • 201
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
Accepted

Define active window for startup in .vimrc

You can do this with a simple autocommand: au VimEnter * wincmd l This tells vim anytime you open a new vim window (VimEnter) on any file type * to run the ex command :wincmd l. wincmd l is ...
DJMcMayhem's user avatar
  • 17.4k
9 votes

What is a scratch window?

A 'scratch' buffer is just an informal term for a place to type arbitrary temporary content. Following the accepted answer and another question, I created the following function in my vimrc. The ...
NeilG's user avatar
  • 191
9 votes

How to apply a setting in all open tabs and windows?

:tabdo windo set number gets the job done, but I don't really like it since it actually switches to each tab and window before running the command. After it finishes running, you'll end up on the ...
Tommy A's user avatar
  • 6,710
8 votes

How to make the two windows equal width when comparing files?

If you want the window widths to remain equal as you change the size of the Vim window, try this in your ~/.vimrc: if exists("##VimResized") if &diff au VimResized * wincmd = ...
garyjohn's user avatar
  • 6,284
8 votes

How can I open a buffer in a new tab leaving the current window and buffer intact?

After some research I found a solution. If you are focused on the buffer/window: :tabe % This opens the current buffer in new tab and leaves the current window intact. why does it leave the old ...
the_velour_fog's user avatar
8 votes

Stop CtrlP from opening in NERDTree

Finally found a way to do this that doesn't involve closing NERDTree all the time. I made a function that cycles through the open windows until it finds a writable buffer, then runs ctrl-p there: ...
DJ Madeira's user avatar
8 votes
Accepted

Any recommendations to enforce use of keybindings rather than equivalent command mode commands?

You could try to add this code in your vimrc: let g:my_overlooked_commands = [ \ { 'old': 'vsplit', 'new': 'C-w v' }, \ { 'old': 'split', '...
user852573's user avatar
  • 1,003
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

Why does :bd # delete the current buffer when no alternate buffer exists?

Evidence Because there is no alternate file you're actually just running plain ol' :bd, deleting the current buffer...try it without # and you'll see the result is the same. A similar thing happens ...
B Layer's user avatar
  • 19.6k
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

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