brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Vim's :vsplit shows two files side by side

Vim
~/tips/tip-vim-split-windows

:vsplit config.example.yml

Puts files next to each other in one Vim screen.

Copying values from one file to another, or checking a function against its test, is easier with both on screen.

:vsplit config.example.yml
:split notes.txt

:vsplit (:vs) opens a file in a new window to the left of the current one, :split (:sp) above it. Without a file name they show the same file twice, which is handy for looking at two parts of a long file.

Moving around uses Ctrl-w and a direction:

Ctrl-w h
Ctrl-w l
Ctrl-w w
Ctrl-w =

h and l go left and right, j and k down and up, w cycles through all windows. Ctrl-w = makes them all the same size again after a terminal resize. :q closes only the current window, and :only closes all the others.

From the shell, vim -O a.txt b.txt opens files side by side right away, and -o stacks them.

If you’d rather have new windows open to the right and below, as most other editors do, these two options flip it:

set splitright splitbelow

I like that yanks and registers are shared between windows, so copying across is just y in one and p in the other.

Further reading: Vim help: :vsplit, Vim help: CTRL-W =

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link