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: vimdiff shows two files side by side and Vim copies changes

Vim
~/tips/tip-vim-vimdiff

vimdiff nginx.conf nginx.conf.new

Compares two files and moves differences between them.

diff shows what differs. vimdiff shows it and lets you fix it right there, which I think is great for merging two versions of a config file.

vimdiff nginx.conf nginx.conf.new

Vim opens both files in vertical splits, scrolls them together, folds away the parts that are the same and highlights the lines that differ. vim -d does the same thing.

Move between differences with ]c and [c. On a difference, two commands copy text across:

dp
do

dp is diff put: it pushes the version under your cursor to the other file. do is diff obtain: it pulls the other file’s version into this one. Switch between the two windows with Ctrl-w w.

Then save what changed, or use :wqa to write and close both.

After lots of manual editing, the highlighting can get out of step with the text. :diffupdate recalculates it. And if whitespace differences drown out the real ones, :set diffopt+=iwhite makes Vim ignore changes in the amount of white space.

Further reading: Vim help: vimdiff, Vim help: dp and do

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