115
votes
Swap the position of two windows
To swap the two parts of a split window simply do: <C-w> <C-r>
63
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 ...
41
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 ...
37
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.
26
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 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 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. ...
19
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 ...
16
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 ...
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.
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 '...
12
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 (...
11
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 ...
11
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 ...
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
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
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 ...
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:
...
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', '...
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}.
...
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", ...
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 ...
8
votes
Accepted
Open split window at far left
You can use a couple of methods to achieve the same end result as your request.
You can just open a vertical split and then move it to leftmost position using Controlw + ShiftH (note that the "h" is ...
7
votes
How to "full screen" browse Vim help?
Another option that gets rid of the pesky extra "new file" tab is
vim +"tab help | -tabc".
This creates a help tab on vim start (tab help) and removes the new file (-tabc).
7
votes
Keep windows reference in memory
I think what you are looking for is the function win_getid() combined to the
function win_gotoid().
:h win_getid()
says:
win_getid([{win} [, {tab}]])
Get the window ID for the specified ...
7
votes
How can I determine if *any* window in the current tabpage is in diff-mode?
You can sum up the values of &diff for each window, and see if the total is > 0:
let any_diff = 0
windo let any_diff += &diff
echo any_diff . ' windows in diff mode'
if any_diff > 0 | do ...
7
votes
Conditional window split
You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:
function Widevsplit()
if ...
7
votes
Accepted
Conditional window split
Try moving the if into the autocommand:
au VimEnter * if winwidth('%') >= 100 | vsplit | endif
7
votes
Prevent a window from resizing
In researching something else, I stumbled across the answer to this question:
set noequalalways
7
votes
Accepted
Can I specify '-o' as the default for vi in my vimrc?
As a solution to the generalized question How can I apply a command-line option every time I open vim? (there are options that don't have configuration equivalents) one approach is as follows.
Put ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vim-windows × 611buffers × 68
neovim × 48
vimrc × 41
vimscript × 39
key-bindings × 39
gvim × 29
tabbed-user-interface × 28
window-management × 18
command-line × 15
netrw × 15
plugin-nerdtree × 15
multiple-files × 14
terminal × 12
autocmd × 12
scrolling × 12
microsoft-windows × 9
vimdiff × 9
terminal-buffer × 8
help-system × 8
statusline × 7
tmux × 7
syntax-highlighting × 6
macvim × 6
quickfix × 6