Full Byte Developer.

Survive any remote box with a Vim quick start

Survive SSH edits with Normal, Insert, and safe quit paths, plus a check for Vim versus nvi.

Published here , updated · 4 sources

The goal on a strange SSH box is survival: open a file, change a line, leave safely. Vim starts in Normal mode, where keys are commands, not text. Press i for Insert, Esc to return to Normal, and : for Command-line quit paths. ZZ writes and exits; colon-q-bang discards [1][2].

Quick start: check which vi you actually have

Before teaching Vim-only tricks, ask the remote host what vi is. FreeBSD, NetBSD, and OpenBSD traditionally ship nvi as the default vi (a smaller Berkeley re-implementation). Treat that lineage note as orientation, not a portability guarantee [3][4].

bash
command -v vi vim nvi 2>/dev/null
readlink -f "$(command -v vi)" 2>/dev/null
vim --version | head -1
vi --version 2>&1 | head -1

Captured on this Debian-derived host:

text
/usr/bin/vi
/usr/bin/vim
/usr/bin/vim.basic
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Aug 24 2026 22:13:04)
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Aug 24 2026 22:13:04)

Sandbox capture on the review host; re-run on your box before you treat the numbers as a lab result.

Here vi resolves to a Vim binary. If nvi is what you have, stick to classic vi motions and the quit paths below until you install Vim on purpose.

Edit, save, and quit without panic

Interactive practice (do this on a throwaway file, not production configs):

text
vim /tmp/vim-demo-fbd/demo.txt
# Normal mode: press i, type text, press Esc
# Save and quit: ZZ
# Or: :wq then Enter
# Abort without saving: colon-q-bang then Enter

Bare :q can fail with E37: No write since last change (add bang to override) when the buffer has unsaved edits [1]. Use colon-q-bang when you mean to discard.

For a non-interactive check that the same editor can rewrite a file:

bash
mkdir -p /tmp/vim-demo-fbd
printf 'line1\nline2\n' > /tmp/vim-demo-fbd/demo.txt
vim -es -u NONE /tmp/vim-demo-fbd/demo.txt <<'EOF'
%s/line1/hello/
wq
EOF
cat /tmp/vim-demo-fbd/demo.txt

Captured output:

text
hello
line2

That proves the editor can rewrite a path without a GUI. Muscle-memory the interactive path (i, Esc, ZZ) before you need it on a broken production box.

day-one Vim modes Normal keys are commands i Insert keys become text Esc Command-line :wq colon-q-bang ZZ in Normal writes and exits; colon-q-bang discards unsaved edits [1]

Normal mode treats keys as commands. Press i to enter Insert where typing becomes text, then Esc to return. Command-line mode handles :wq and colon-q-bang. ZZ in Normal writes and exits so you can leave a remote edit safely.

Keep the day-one set small

Teach Normal, Insert, and Command-line first. Mention Visual mode only as "select, then act" if someone asks. Do not start remote sessions with destructive macros on production files. Prefer a dedicated scratch file under /tmp until the quit paths are muscle memory.

Minimal motion set that covers most rescue edits:

  • h j k l move one character or line
  • 0 and end-of-line ($ in Vim help) jump to line start and end
  • dd deletes a line in Normal (practice on the scratch file)
  • u undoes the last change

Stop there on day one. Search, macros, and plugins wait until you can exit without closing the SSH window [1][2].

Mistakes that trap people on SSH boxes

Closing the terminal window because :q printed E37. Use colon-q-bang or ZZ instead [1].

Treating every vi as Vim. Check --version before relying on Vim-only syntax [3][4].

Editing /etc files before practicing on /tmp. One wrong dd on a real config is enough.

Staying in Insert while trying to run Normal commands. Press Esc until you are sure, then try again.

Typing Ctrl+S by accident and thinking Vim froze. That is terminal flow control; see terminal stuck recovery before you kill the session.

Depth: why modes exist

Normal mode keeps the keyboard free for operators. Insert mode is the rare state where typing inserts. Command-line mode is for ex commands such as write and quit [1]. That split is why beginners feel "stuck": they are in the wrong mode for the key they pressed. The fix is always the same: Esc to Normal, then choose Insert or :.

When the box is reached through SSH aliases, keep the Host block short so reconnecting after a bad edit is two words. Pair this page with SSH config aliases and top terminal commands part 1.

A five-minute drill you can repeat

  1. Create /tmp/vim-demo-fbd/notes.txt with one line of text.
  2. Open it in Vim. Press i, append a word, press Esc.
  3. Save with ZZ. Re-open and confirm the word stuck.
  4. Open again, change something, leave with colon-q-bang, re-open and confirm the discard.
  5. Run the vim -es rewrite snippet once so you trust non-interactive edits too.

Repeat that drill on the next unfamiliar host before you touch production configs. The host that ships nvi will still honor the classic quit paths even when Vim-only features are missing [3][4].

When something still feels frozen

If the screen stops updating after Ctrl+S, press Ctrl+Q. If SSH itself is wedged, use the tilde escape from terminal stuck recovery. If Vim is merely waiting in the wrong mode, Esc then colon-q-bang is still the safe abort. Closing the window kills every job in that session, which is how people turn a small edit into an outage.

Write versus quit, said plainly

Three exits cover almost every panic:

  1. ZZ in Normal: write the file if needed, then quit [1].
  2. :wq then Enter: same intent, typed on the command line.
  3. colon-q-bang then Enter: quit and throw away the buffer [1].

:w alone writes and leaves you inside Vim. :q alone quits only when nothing changed; otherwise you meet E37 [1]. Say the intent out loud before you type: "save and leave" versus "leave and discard." That one sentence prevents half of the closed-window stories.

Count lines before you delete

On a rescue edit, jump with 0 and $, fix the typo in Insert, then leave. If you must delete a bad line, glance at the line number (Ctrl+G shows position in many builds) before dd [1]. Undo with u immediately if the wrong line vanished. Macros, global substitutes, and plugins wait until those habits are boring.

Some hosts only offer nvi. Classic motions and the quit paths above still apply; Vim-only :help pages and some visual tricks may not [3][4]. When you control the box, install Vim on purpose and keep using the same survival set.

Pair the editor with a short SSH alias

Long ssh -i ... -p ... lines make people rush the edit because reconnecting hurts. Put the Host block in place first (SSH config aliases), then practice Vim on /tmp. Reconnect should be two words so a bad buffer is cheap to abandon with colon-q-bang.

What to ignore on day one

Skip .vimrc customization until you can exit cleanly on a stock binary. Skip plugins, status lines, and color schemes on a rescue box. Skip Visual mode until Normal, Insert, and the three quit paths are automatic [1]. The user manual usr_02 is intentionally small; that is the point for remote survival [1][2].

If the host opens nano when you type EDITOR=nano, that is fine for that session. This page is for the common case where vi or vim is what you get, including when a tool drops you into $EDITOR mid-incident. Know the escape hatches before the incident, not during it.

One more non-interactive check

After the %s rewrite demo, confirm you can append a line without a TTY:

bash
vim -es -u NONE /tmp/vim-demo-fbd/demo.txt <<'EOF'
a
third
.
wq
EOF
cat /tmp/vim-demo-fbd/demo.txt

Captured output:

text
hello
line2
third

If that fails on nvi, fall back to the interactive i / Esc / ZZ path and treat ex-mode scripts as Vim-only until you verify [3][4].

Browse the Dev explainers topic.

Send this to the friend who got stuck in vim on a server and closed the window.

A dark editor slab split into a calm navy normal-mode pane and a glowing amber insert-mode pane, with a teal pipe running from the slab into a stacked remote cube, on a navy grid with small unmarked geometric accents and no typography, keys, or figures.
Reach the box, switch modes, and keep a safe quit path before you edit.

Keep this guide

By Full Byte Developer

Filed under Dev explainers, Dev tools

Questions about this guide

Is vi always Vim on Linux servers?

No. On many Debian-derived boxes vi is a Vim binary, but some BSD-family systems ship nvi as the default vi. Run vim --version or vi --version on the host you are on before relying on Vim-only features.

How do I quit without saving?

From Command-line mode, colon-q-bang quits and overrides unsaved changes. Bare :q can refuse with E37 when the buffer changed. ZZ in Normal mode writes and exits.

Do I need Visual mode on day one?

No. Survive with Normal, Insert, and Command-line quit paths first. Treat Visual as select-then-act once those three are automatic.

Sources

Next in this stack