Real-World Vim Workflows
Tested, step-by-step Vim workflows for daily engineering work: server configs and swap recovery, Git commits and rebases, project-wide replace, :make, merge conflicts, sessions, big files.
By The Dark DebuggerUpdated 24 min read
This is the capstone of the Vim track. Each section is one job you'll actually do, walked through step by step with the commands and output from a real run: editing a service config on a server and recovering after a dropped connection, writing commits and cleaning up history with Git, renaming something across a project, compiling and linting with the quickfix list, resolving a merge conflict in diff mode, saving a working layout, and handling files too big or too long-lined for comfort. It uses everything from the earlier articles, especially Buffers, Windows, and Tabs, Ex Commands, Ranges, and :global and Configuring Vim.
Why workflows, not more commands
By now you know more Vim commands than most people who use it every day. What separates fast
Vim users is not the number of commands they know but a handful of routines they don't have to
think about: the quickfix loop, vimdiff, :cdo, swap-file recovery. These are also the
places where people fall back to another tool, because the first attempt hit an error message
nobody explained. Each section below includes the errors I actually hit while testing.
1. Editing a service config on a server
On servers you edit as a privileged user, often over SSH, often with a minimal Vim, and a typo can take a service down. The routine: open, edit, validate before reloading, and know how to recover when the connection drops.
Validate from inside Vim
Here is a systemd unit with a typo on line 7:
[Unit]
Description=Checkout API
After=network-online.target
[Service]
User=checkout
ExecStrat=/usr/bin/env python3 -m http.server 8080
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.targetMost config formats have a checker (nginx -t, sshd -t, visudo -c, systemd-analyze verify). Run it on the file you're editing without leaving Vim; % is the file name:
:!systemd-analyze verify %/home/sid/wf/srv/checkout.service:7: Unknown key name 'ExecStrat' in section 'Service', ignoring.
checkout.service: Service has no ExecStart=, ExecStop=, or SuccessAction=. Refusing.
[…]
Unit checkout.service has a bad unit file setting.
shell returned 1(The trimmed line was an unrelated permission warning about another unit on my test machine.)
/ExecStrat<CR>, cwExecStart<Esc>, :w, and the same :!systemd-analyze verify % no
longer mentioned checkout.service. Only then reload the service.
Writing files you don't own
If you opened a root-owned file as a normal user, Vim refuses to write it. The clean fix is to
not get there: sudoedit /etc/nginx/nginx.conf (or sudo -e) copies the file to a temporary
location, opens it in your editor as you (with your vimrc), and copies it back as root when
you quit. The well-known emergency trick from inside Vim is:
:w !sudo tee % > /dev/nullIt pipes the buffer to sudo tee, which writes the file as root. My test lab has no sudo
rights, so neither command was run for this article. The netrw plugin can also edit remote
files directly (vim scp://deploy@web01//etc/nginx/nginx.conf); that wasn't tested here
either, as the lab has no SSH server.
When the connection drops: swap files and vim -r
Vim keeps your unsaved changes in a swap file (.checkout.service.swp next to the file, unless
your vimrc moves it, as the starter vimrc does). To reproduce a dropped SSH session, I opened
the unit in Vim inside tmux, changed RestartSec=5 to RestartSec=10 without saving, and
killed the tmux session, which sends the same hang-up signal a dead SSH connection does. The
file on disk still said RestartSec=5, and the swap file was still there:
-rw-r--r-- 1 sid sid 12288 Nov 9 22:01 .checkout.service.swp
-rw-r--r-- 1 sid sid 206 Nov 9 22:01 checkout.serviceOpening the file again:
E325: ATTENTION
Found a swap file by the name ".checkout.service.swp"
owned by: sid dated: Mon Nov 09 22:01:55 2026
file name: /home/sid/wf/srv/checkout.service
modified: YES
[…]
process ID: 68075
While opening file "checkout.service"
dated: Mon Nov 09 22:01:52 2026
(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r checkout.service"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".checkout.service.swp"
to avoid this message.
Swap file ".checkout.service.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:Read the two lines that matter: modified: YES (there are unsaved changes in the swap file)
and the process ID. If it said (STILL RUNNING), someone (maybe you, in another terminal) is
editing the file right now; choose Q and find that session. Here the process was gone, so:
-
Press
Q, then recover explicitly:vim -r checkout.service. Vim reports:Using swap file ".checkout.service.swp" Original file "/home/sid/wf/srv/checkout.service" Recovery completed. You should check if everything is OK. (You might want to write out this file under another name and run diff with the original file to check for changes) You may want to delete the .swp file now. -
Check the change (
RestartSec=10was back), then:w. -
Quit, and open the file once more. The warning appears again, now saying the file is
NEWER than swap file!, and because no Vim process owns the swap file, the prompt includes(D)elete it. PressD. The swap file is gone and the next open is clean.
vim -r with no file name lists every swap file Vim can find, which is useful after a crash
when you don't remember what you were editing.
2. Vim as Git's editor
Git opens $GIT_EDITOR, core.editor, $VISUAL or $EDITOR (in that order) for commit
messages and interactive rebases. To make it Vim for the current repository:
git config core.editor vimAdd --global to make it the default for every repository. (In the lab I set it per test
repository, with the same -u DEFAULTS options as everywhere else in this track.)
Writing a commit message
git commit without -m opened this (80x16 terminal):
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Changes to be committed:
# modified: ratelimit.conf
#Vim recognised the file as a Git commit message, so the gitcommit filetype plugin was
active. Its most useful effect: :set textwidth? reported textwidth=72, so the body wraps
automatically at 72 columns, the width Git tools expect. I typed a subject line, a blank line,
and one long sentence; Vim wrapped it as I typed:
Allow short bursts above the rate limit
Checkout traffic spikes when a promotion email goes out, and a hard
limit of 100 requests per second rejected real customers. A burst of 20
absorbs the spike.:wq finishes the commit, and git log -1 --format=%B printed exactly those lines. To
abandon a commit from inside the editor, quit with an error code using :cq. Git noticed:
hint: Waiting for your editor to close the file... error: There was a problem with the editor 'vim -u DEFAULTS -i NONE'.
Please supply the message using either -m or -F option.and the commit was not created (exit status 1). Deleting all lines and saving also aborts,
but :cq is quicker and works even when you're halfway through an interactive rebase.
Cleaning up history with git rebase -i
Before opening a pull request, four commits where two are noise:
git log --onelineb6233c8 address review comments
0f0bb7e Add circuit breaker
3bf7ba1 fix typo
3544884 Add retry with backoff for payment calls
1cdcdb4 Allow short bursts above the rate limit
fa98d4b Initial rate limit configgit rebase -i HEAD~4 opened the todo list in Vim, oldest commit first:
pick 3544884 Add retry with backoff for payment calls
pick 3bf7ba1 fix typo
pick 0f0bb7e Add circuit breaker
pick b6233c8 address review comments
# Rebase 1cdcdb4..b6233c8 onto 1cdcdb4 (4 commands)This file is ideal for Ex commands. fixup melds a commit into the one above it and drops its
message:
:2s/^pick/fixup/
:4s/^pick/fixup/pick 3544884 Add retry with backoff for payment calls
fixup 3bf7ba1 fix typo
pick 0f0bb7e Add circuit breaker
fixup b6233c8 address review comments:wq, and Git replied Successfully rebased and updated refs/heads/main.:
8169a29 Add circuit breaker
3da7e2d Add retry with backoff for payment calls
1cdcdb4 Allow short bursts above the rate limit
fa98d4b Initial rate limit configReordering commits is :m (:3m0 moves line 3 to the top) and dropping one is dd. :cq
aborts the whole rebase: when I tried it on a later rebase, Git printed There was a problem with the editor, exited with status 1, and git log showed the history unchanged.
3. Project-wide search and replace
Renaming a config key, db_host to database_host, across a small project:
grep -rn 'db_host' ../scripts/migrate.sh:2:db_host="${DB_HOST:-localhost}"
./scripts/migrate.sh:3:psql -h "$db_host" -f migrations/001_init.sql
./docs/setup.md:1:Set `db_host` in deploy/values.yaml.
./deploy/values.yaml:2: db_host: db-primary.internal
./app/db.py:1:from app.config import db_host, db_port
./app/db.py:5: return f"postgresql://{db_host}:{db_port}/shop"
./app/config.py:4:db_host = DB_HOSTThe upper-case DB_HOST environment variable must not change. The routine has three steps:
find with :vimgrep, review in the quickfix list, change with :cdo or :cfdo.
Step 1: find
:vimgrep /\<db_host\>/gj **/*.py **/*.yaml **/*.sh **/*.md\< and \> are word boundaries, g records every match on a line (not just the first),
and j stops Vim from jumping to the first match. ** searches subdirectories.
Step 2: review
:copen opens the quickfix window: one line per match, and Enter on a line jumps there. This
is what it showed for the first four file types (before I added **/*.md):
app/config.py|4 col 1-8| db_host = DB_HOST
app/db.py|1 col 24-31| from app.config import db_host, db_port
app/db.py|5 col 28-35| return f"postgresql://{db_host}:{db_port}/shop"
deploy/values.yaml|2 col 3-10| db_host: db-primary.internal
scripts/migrate.sh|2 col 1-8| db_host="${DB_HOST:-localhost}"
scripts/migrate.sh|3 col 11-18| psql -h "$db_host" -f migrations/001_init.sqlCheck it the way you'd review a diff. If an entry shouldn't change, delete it from the list
first: :packadd cfilter loads a bundled package whose :Cfilter! docs removed the
docs/setup.md entry from the list when I tried it.
Step 3: change and save
:cdo runs a command on every entry, :cfdo on every file in the list:
:cdo s/\<db_host\>/database_host/g | update"app/config.py" 5L, 133B written
"app/db.py" 5 lines, 105 bytes
"app/db.py" 5L, 111B written
"app/db.py" 5L, 117B written
[…]
"docs/setup.md" 1L, 43B written:cdo wrote app/db.py twice, once per match. :cfdo %s/\<db_host\>/database_host/ge | update
does one pass per file instead, and is the better choice when a file has many matches. Either
way, check the result from the shell (or with git diff):
app/config.py | 2 +-
app/db.py | 4 ++--
deploy/values.yaml | 2 +-
docs/setup.md | 2 +-
scripts/migrate.sh | 4 ++--
5 files changed, 7 insertions(+), 7 deletions(-):vimgrep uses Vim's own regex engine and reads every file into Vim, which is slow on big
trees. :grep runs an external program instead (:set grepprg? showed grep -n $* /dev/null
by default) and fills the same quickfix list: :grep -rw DB_HOST . found the three lines
containing the environment variable. Many people set grepprg to rg --vimgrep for speed.
4. Compiling and linting with :make and the quickfix list
:make runs makeprg (by default make), reads its output with errorformat, and turns
every error into a quickfix entry you can jump to. Here is a small C program with three
mistakes and a Makefile with warnings on:
CFLAGS = -Wall -Wextra -O2
stock: stock.o
$(CC) $(CFLAGS) -o $@ $^static int total(const struct item *items, int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += items[i].quantity
return sum;
}
int main(void)
{
struct item stock[] = {{"KB-101", 12}, {"MS-220", 4}};
printf("%s units\n", total(stock, 2));
return count;
}In Vim, :make showed GCC's normal output, then put the cursor on the first error. The
status line read:
(3 of 23): error: expected ‘;’ before ‘return’23 lines of compiler output, but only some are errors with a location. :clist shows just
those:
3 stock.c:12 col 33: error: expected ‘;’ before ‘return’
9 stock.c:14 col 1: warning: no return statement in function returning non-void [-Wreturn-type]
13 stock.c:19 col 14: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
19 stock.c:20 col 12: error: ‘count’ undeclared (first use in this function)
22 stock.c:20 col 12: note: each undeclared identifier is reported only once for each function it appears inThe fix loop is: fix, :cnext, fix, :cnext, then :make again. Exactly what I typed:
| Keys | Status line afterwards | Fix |
|---|---|---|
(after :make) | (3 of 23): error: expected ‘;’ before ‘return’ | A;<Esc> |
:cnext | (9 of 23): warning: no return statement… | nothing: caused by the missing ; |
:cnext | (13 of 23): warning: format ‘%s’ expect… | rd (cursor is on the s) |
:cnext | (19 of 23): error: ‘count’ undeclared… | ciw0<Esc> |
Then :w and :make:
cc -Wall -Wextra -O2 -c -o stock.o stock.c
cc -Wall -Wextra -O2 -o stock stock.oand :!./stock printed 16 units. Other quickfix commands: :cprev, :cfirst, :clast,
:copen/:cclose, and :colder/:cnewer to go back to a previous list.
Linters: :compiler and vim -q
The same loop works for any tool that prints file:line:col: message. Vim ships compiler
definitions that set makeprg and errorformat together; for ShellCheck:
:compiler shellcheck
:set makeprg?
:make % makeprg=shellcheck -f gccOn a deploy script, :make % produced five entries:
deploy.sh:5:4: note: Double quote to prevent globbing and word splitting. [SC2086]
deploy.sh:6:10: error: Iterating over ls output is fragile. Use globs. [SC2045]
deploy.sh:6:15: note: Use ./*glob* or -- *glob* so names with dashes won't become options. [SC2035]
deploy.sh:7:12: note: Double quote to prevent globbing and word splitting. [SC2086]
deploy.sh:9:6: note: Double quote to prevent globbing and word splitting. [SC2086]and the cursor landed on the first one: (1 of 5) note 2086: Double quote to prevent globbing and word splitting.
To start Vim with a quickfix list from any command, use -q with process substitution:
vim -q <(shellcheck -f gcc deploy.sh deploy2.sh)That opened Vim on the first problem with all ten entries from both scripts in :clist. It's
a good way to work through CI lint failures: copy the failing command, prefix it with
vim -q <(…).
5. Diff mode and merge conflicts
Comparing two files
vim -d a b (or vimdiff a b) shows files side by side with differences highlighted and
identical regions folded. Production and staging configs, 100x16 terminal:
[server] | [server]
port = 8080 | port = 8080
workers = 8 | workers = 2
|
[database] | [database]
host = db-primary.internal | host = db-staging.internal
pool_size = 20 | pool_size = 5
|
[logging] | [logging]
level = warn | level = debug
------------------------------------------------| format = json
~ |~
app.prod.ini 1,1 All app.staging.ini 1,1 All(Colours don't survive a text capture; the dashes mark a line that exists only on the right.)
| Keys | Action |
|---|---|
]c / [c | next / previous change |
do | "diff obtain": take the other window's version of this change |
dp | "diff put": push this window's version to the other |
:diffupdate | recompute the diff after manual edits |
:diffget / :diffput | the Ex versions, which accept a buffer name |
In the prod window I pressed ]c three times to reach the logging block and do; after
:wqa, app.prod.ini ended with level = debug and format = json, copied from staging. To
compare two windows you already have open, run :windo diffthis; :diffoff! turns it off.
Resolving a merge conflict with git mergetool
Two branches changed the same lines of app.ini:
git merge tune-workersAuto-merging app.ini
CONFLICT (content): Merge conflict in app.ini
Automatic merge failed; fix conflicts and then commit the result.git config merge.tool vimdiff
git config mergetool.keepBackup false
git mergetoolGit opened four windows: our version (LOCAL), the common ancestor (BASE) and their version (REMOTE) on top, and the file being merged (MERGED, with conflict markers) at the bottom, where the cursor starts. The top half, 120x30 terminal:
1 [server] | 1 [server] | 1 [server]
2 port = 8080 | 2 port = 8080 | 2 port = 8080
3 workers = 6 | 3 workers = 4 | 3 workers = 8
---------------------------------| ----------------------------------| ---------------------------------
4 | 4 | 4
5 [cache] | 5 [cache] | 5 [cache]
6 host = redis-02.internal | 6 host = redis.internal | 6 host = redis.internal
7 ttl = 300 | 7 ttl = 300 | 7 ttl = 600
[…]
<app_LOCAL_84471.ini 1,1 All ./app_BASE_84471.ini 1,1 All <pp_REMOTE_84471.ini 1,1 AllThe BASE column explains the conflict: our branch moved the cache to redis-02 and set 6
workers; theirs set 8 workers and a longer TTL. The result I wanted: 8 workers, redis-02,
TTL 600. In the MERGED window:
gg]c first change: the whole conflict block
:diffget RE<CR> take REMOTE's version (buffer name match on "RE")
]c next change: host and ttl, compared with LOCAL
:diffget LO<CR> take LOCAL's version: host = redis-02.internal, ttl = 300
:diffupdate<CR>
/^ttl<CR>wwcw600<Esc> adjacent lines form one hunk, so fix ttl by hand
:wqa<CR>:diffget works on whole hunks, and host and ttl were adjacent, so taking LOCAL's hunk
brought ttl = 300 with it. A manual edit for the last line is normal. After :wqa, the
merged file was:
[server]
port = 8080
workers = 8
[cache]
host = redis-02.internal
ttl = 600git status --short showed M app.ini (staged, conflict resolved), and git commit -m "Merge tune-workers" completed the merge.
6. Sessions: saving a layout
A session file records your buffers, windows, tab pages, current directory and more, so a complicated layout comes back with one command. I built two tab pages (app.ini next to nginx.conf; the log above worker.ini) and saved them:
:mksession! ~/shop-session.vimThe file is a Vim script (674 lines here). Starting Vim with it restores everything:
vim -S ~/shop-session.vimTab page 1
conf/nginx.conf
conf/app.ini
Tab page 2
> conf/worker.ini
logs/app.logWhat gets saved is controlled by sessionoptions:
sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,terminalI remove options (set sessionoptions-=options): otherwise the session also saves option
values and mappings, and later changes to your vimrc seem not to work in restored sessions.
Undo history, registers and marks are not part of a session; undofile and the viminfo file
handle those.
7. Big files and very long lines
Vim copes with large files better than its reputation suggests. I generated a 400,000-line, 25 MB application log in a RAM disk and timed opening it, jumping to the end, and quitting (each figure from the second of two runs):
defaults: open, G, quit 0.10s
-u NONE -n: open, G, quit 0.10s
defaults: %s with undo 0.46s
defaults: %s, undolevels=-1 0.41sThe global substitute changed 228,965 lines in under half a second; turning off undo for it
saved about 10%. Opened with vim -u NONE, Vim's memory use peaked at 38 MB (measured with
/usr/bin/time). So for files in the tens of megabytes,
just open them. For gigabyte-sized files, which I didn't test (the lab rules forbid creating
files that large), the usual advice holds: use less, grep or tail, and bring only the
interesting part into Vim. Vim reads standard input with -:
grep 'ERROR \[payment\]' app.log | vim -"-stdin-" 14410L, 963830B14,410 lines instead of 400,000, in a buffer you can search, sort and save under a new name.
Long lines are the real problem. A 4.7 MB minified JSON file is a single line. Opening it and drawing the first screen:
defaults: open, redraw, quit 2.18s
-u NONE: open, redraw, quit 0.16s
defaults + syntax off: redraw 0.15s
defaults + nowrap: redraw 0.36s(The very first run took 7.78 s, with cold caches.) Syntax highlighting on one enormous line
costs over two seconds per full redraw, and every scroll is a redraw. :syntax off in that
buffer, or vim -u NONE, fixes it. Better still, give the data lines: jq . catalog.json > pretty.json produced a 600,004-line file that opened, jumped to the end and redrew in half a
second with syntax highlighting on.
Where you'll use this
These routines map directly onto daily engineering work:
- On-call and operations: editing configs on servers, validating them with
:!checker %before reloading, recovering after a dropped SSH session withvim -r. - Code review and Git hygiene: proper commit messages with the 72-column wrap, squashing
fixups in
git rebase -iwith:sand:g, resolving conflicts ingit mergetool. - Refactoring:
:vimgrepor:grep, review in:copen,:cdo … | update,git diffto verify. - Fixing CI failures:
vim -q <(the failing lint command)or:make, then the:cnextloop until it passes. - Log analysis:
grep … | vim -, then the:g,:sortand filter techniques from Ex Commands, Ranges, and :global.
Common mistakes
:cdo stops with E37 after the first file
My first run of the rename, without | update and without hidden, stopped immediately:
(1 of 6): db_host = DB_HOST
E37: No write since last change (add ! to override):cdo moves between files, and Vim won't leave a modified buffer unless hidden is set.
Either end the command with | update, or set hidden (the starter vimrc does) and write
everything with :wa after reviewing.
:cdo s//…/ with an empty pattern
In Normal editing, :s//new/ reuses the last search pattern. After :vimgrep, it didn't:
E35: No previous regular expression:vimgrep didn't set the search pattern. Spell the pattern out in the substitute.
Choosing (E)dit anyway at the swap-file prompt
E opens the file from disk and ignores the swap file, so the unsaved changes it contains
stay hidden. If you then save, the swap file still exists and still contains the old changes,
and the warning comes back next time. Decide first: recover (R or vim -r), or delete
(D) if you know the changes don't matter.
Expecting :diffget to take a single line
Adjacent changed lines form one hunk, and :diffget takes all of it. In the merge above,
taking LOCAL's host brought LOCAL's ttl along. Use :diffget for the bulk, then edit the
remaining lines by hand, and run :diffupdate if the highlighting looks stale.
Summary
- Validate configs from Vim with
:!checker %before reloading a service; usesudoeditrather than running Vim as root. - After a crash or dropped connection,
vim -r filerecovers from the swap file; readmodified:and the process ID in E325 first, and delete the swap file once you're done. - Git uses Vim for commits (
textwidth=72from thegitcommitplugin) and rebases; edit the todo list with:s/:g/:m, and:cqaborts either. - Project-wide changes:
:vimgrep /pat/gj **/*.extor:grep, review with:copen, then:cdo s/…/…/g | updateor:cfdo %s/…/…/ge | update. :makeplus the quickfix list (:clist,:cnext) turns compiler and linter output into a to-do list;:compiler shellcheckandvim -q <(cmd)work for anyfile:line:coltool.- Diff mode:
]c,do,dp,:diffget RE/LOingit mergetool; hunks, not lines. :mksessionandvim -Ssave and restore layouts; consider removingoptionsfromsessionoptions.- Tens of megabytes are fine; long lines with syntax highlighting are slow, so
:syntax offor reformat withjq .; pipe extracts of huge files intovim -.
Exercises
Open a config file in Vim inside tmux (or any terminal you can kill), change a line without saving, and kill the terminal. Recover the change and leave no swap file behind.
Show Solution
vim -r checkout.serviceRecovery completed. You should check if everything is OK.Check the recovered line, :w, :q. Open the file again: the E325 prompt now says the file
is NEWER than swap file! and offers (D)elete it. Press D. Running ls -la afterwards
showed only checkout.service, no .swp file.
Use :compiler shellcheck and :make % on the deploy.sh from section 4, and fix every
finding by moving through the quickfix list.
Hint
Quote the variables, replace $(ls *.tar.gz) with a glob, and give DEPLOY_ENV a default so
set -u doesn't trip over it.
Show Solution
#!/usr/bin/env bash
set -euo pipefail
release_dir="/srv/checkout/releases/$1"
cd "$release_dir"
for f in ./*.tar.gz; do
tar -xzf "$f"
done
if [ "${DEPLOY_ENV:-}" == "prod" ]; then
echo "deploying to production"
fiWith this version :make % produced no entries, and shellcheck -f gcc in the shell printed
nothing and exited with status 0.
In a rebase todo list like the one in section 2, mark every commit whose message starts with
fix or address as fixup, with a single Ex command, so that it works no matter how many
there are.
Show Solution
:g/^pick \x\+ \(fix\|address\)/s/^pick/fixup/pick 14d7c5a Add retry with backoff for payment calls
fixup b24a9b6 fix typo
pick 514efab Add circuit breaker
fixup 0b6208b address review comments\x\+ matches the hexadecimal commit hash. After :wq, git log --oneline showed three
commits: Add circuit breaker, Add retry with backoff for payment calls and the initial
commit. Each fixup commit is melded into the line above it, so order matters: a fixup must
come right after the commit it fixes.
Recreate the small project from section 3 (app/, deploy/, scripts/, docs/) and rename
db_host to database_host everywhere, writing each file only once, without touching
DB_HOST.
Show Solution
:vimgrep /\<db_host\>/gj **/*.py **/*.yaml **/*.sh **/*.md
:cfdo %s/\<db_host\>/database_host/ge | update:cfdo visits each file once, and %s changes every match in it. git diff --stat reported
5 files changed, 7 insertions(+), 7 deletions(-), and grep -rn DB_HOST still found the
environment variable unchanged, because the search is case-sensitive and uses word
boundaries.
Create a repository where main sets workers = 6 and host = redis-02.internal, and a
branch sets workers = 8 and ttl = 600, starting from workers = 4, host = redis.internal, ttl = 300. Merge, then use git mergetool with vimdiff to produce
workers = 8, host = redis-02.internal, ttl = 600.
Show Solution
In the MERGED window:
gg]c:diffget RE<CR>
]c:diffget LO<CR>
:diffupdate<CR>
/^ttl<CR>wwcw600<Esc>
:wqa<CR>[server]
port = 8080
workers = 8
[cache]
host = redis-02.internal
ttl = 600Then git commit -m "Merge tune-workers". The hand edit is needed because host and ttl
are adjacent and form one hunk; :diffget can't take one without the other.
Tested with: Vim 9.1 (Ubuntu 24.04 package 9.1.0016) on Ubuntu 24.04 (WSL2), November 2026,
with Git 2.43.0, GCC 13.3.0, ShellCheck 0.9.0, systemd 255's systemd-analyze and jq 1.7.
Every walkthrough ran in a real terminal under tmux, started as vim -u DEFAULTS; screens and
messages are captures, trimmed where marked. The dropped connection was simulated by killing
the tmux session. Not run: sudoedit, :w !sudo tee % (no sudo in the lab), scp:// editing
(no SSH server), and files in the gigabyte range (lab disk rules); the big-file timings used
files in a RAM disk that were deleted afterwards. Paths from the test machine's scratch directories are shown shortened to /home/sid/….
Written by The Dark Debugger
Engineer documenting the things that took me too long to learn, so they take you less time. Every Vim tutorial here is tested end to end before publishing.