A common workflow in vim is to use multiple windows to view and edit various files at the same time. Once opened though, the size of each window often remains unchanged unless explicitly resized.
A nicer workflow would be for the focused window’s width to automatically expand.
augroup ReduceNoise autocmd! " Automatically resize active split to 85 width autocmd WinEnter * :call ResizeSplits() augroup END function! ResizeSplits() set winwidth=85 wincmd = endfunction
to 85. This settings controls the width for the active window; the number represents the number of columns for the active window including the sign and line number columns. If those require 5 columns and
is set to 85, 80 columns are used for the text.
, equalizes the width and height for all the other unfocused windows; see
: h wincmd
for more information and some other great window commands.
The above is a slimmed down version of a more practical implementation. Controlling other window settings can reduce additional noise on unfocused windows increasing your signal to noise ratio fo r your active work. Some additional ideas include:
- Display absolute line numbers in unfocused windows and relative line numbers only in the focused window
- Only display the sign column in the focused window
- Only show the cursor line in the focused window
- Disabling syntax settings of the unfocused windows
Enabling these settings is easily done by extending the above autogroup to include some additional auto commands like the ones shown below.
autocmd WinEnter * setlocal cursorline autocmd WinEnter * setlocal signcolumn=auto autocmd WinLeave * setlocal nocursorline autocmd WinLeave * setlocal signcolumn=no
are enabled. Unfocused windows disable these settings.
The autocommands and resizing function work well in most cases, but may have some unintended effects. Windows created by plugins like NERDTree or to display the quick fix and location list may expand unexpectedly when focused.
to run when on these windows as it equalizes not just the width but also the height of all open windows.
Despite these (minor) shortcomings (most of which can be accounted for and fixed), this has become one of my favorite and most useful settings. Its a pattern you won’t know you missed until you had it.