107
votes
Swap the position of two windows
To swap the two parts of a split window simply do: <C-w> <C-r>
60
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 ...
35
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.
32
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 ...
26
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
...
25
votes
How can I make Vim open help in a vertical split?
You can use :vert h [your topic] to open help vertically.
You can use the following command:
cnoreabbrev H vert h
To make vim replace H by vert h automatically in command line.
Also you can use ...
24
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 ...
23
votes
Accepted
How to make the two windows equal width when comparing files?
You can equalize the size of windows with <c-w>=.
21
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
20
votes
Accepted
What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?
I tried googling for this with different sets of keywords, and struck gold on one such attempt with this result:
https://web.archive.org/web/20220121051339/https://developer.ibm.com/tutorials/l-vim-...
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 ...
17
votes
What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?
To complete the @sundar answer:
You can log the order of the events simply with a logging function:
augroup EventLoggin
autocmd!
autocmd BufNewFile * call s:Log('BufNewFile')
autocmd BufReadPre *...
16
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. ...
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 to map two commands with only one key
You can do this with \| on unix in the .vimrc file, or with <bar> on windows in the _vimrc file.
e.g.
" unix
nnoremap <C-[> :set columns+=1 \| lines+=1<CR>
" windows
...
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.
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 ...
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
How to map two commands with only one key
I would recommend you to use for example <C-P>, since <C-[> is the same as <Esc> and <C-]> is used to jump to a definition of the keyword under the cursor.
You can just do ...
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 ...
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. ...
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 to bind a set of buffers to a tab?
Mhh, i did not find any plugin out there, but you could write it yourself. You need to learn vimscript for this. I just implemented the functionality that you can switch between buffers in a tab (no ...
9
votes
How can I make Vim open help in a vertical split?
This is inspired from junegunn 's vimrc:
augroup vimrc_help
autocmd!
autocmd BufEnter *.txt if &buftype == 'help' | wincmd L | endif
augroup END
9
votes
Accepted
Emacs switch-window for vim
Oh yes, there sure is: vim-choosewin.
The animated demo from plugin's page:
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 ...
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 ...
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 ...
9
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 (...
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 =
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vim-windows × 305buffers × 43
split × 36
vimscript × 30
vimrc × 29
neovim × 28
gvim × 23
key-bindings × 20
tabbed-user-interface × 18
window-management × 14
plugin-nerdtree × 11
autocmd × 10
terminal × 8
microsoft-windows × 7
netrw × 7
command-line × 6
terminal-buffer × 6
scrolling × 6
help-system × 6
colorscheme × 5
normal-mode × 4
functions × 4
plugin-system × 4
macvim × 4
options × 4