How to Edit Files on a VPS: nano vs vim — Which to Use and When

Practical comparison of nano and vim for editing configuration files on a Linux VPS. Essential commands, shortcuts, advantages, and when to switch from one to the other.

Editing configuration files directly on the server is one of the most common tasks when administering a Linux VPS — tweaking nginx, modifying /etc/hosts, editing environment variables, configuring SSH. For those just starting out, the choice between nano and vim defines the experience: nano is friendly and feels like a regular text editor; vim is minimalist, modal, and has a reputation for being intimidating.

This tutorial compares both editors in practice, shows the essential commands for each one, and helps you decide which to use based on the type of task. The target audience is the beginner sysadmin or developer who connects via SSH to a VPS and needs to edit files without panic — whether it’s tweaking a single line quickly or working efficiently on large files.

Estimated time: 15 minutes to read and test the commands on a test VPS. If you just want to know which one to install right now, jump straight to “When to use nano vs vim”.

Prerequisites

Prerequisites

You need a Linux VPS running Ubuntu 22.04 or 24.04 (Debian also works), SSH access with a sudo user, and a terminal capable of displaying UTF-8 characters. The installation commands assume apt — adapt them to dnf or yum on RHEL/AlmaLinux/Rocky.

Nano — package nano
Full vim vim
Verify install which nano | which vim
System default editor $EDITOR / $VISUAL

Before choosing, confirm what’s already installed. On almost every official Ubuntu image, nano comes by default; vim usually ships in the “tiny” variant (without syntax highlighting). For production, it’s always worth installing the full version of whichever editor you’ll be using to avoid surprises.

Head-to-head comparison: nano vs vim

Both editors solve the same basic problem — editing files in the terminal — but they have opposite philosophies. This table summarizes the differences that matter for the decision.

Featurenanovim
Learning curveLow (5 minutes)High (weeks to fluency)
Modal (insert and command modes)NoYes (normal, insert, visual, command)
Shortcuts visible on screenYes (footer always displays them)No (must memorize)
Macros and bulk editingLimitedExcellent (regex, macro recording)
Binary size~250 KB~3 MB (full vim)
Exit without savingCtrl+X then NEsc, then :q!
Default syntax highlightingDecent (10+ languages)Comprehensive (200+ languages)
Multi-buffer / splitNoYes (:split, :vsplit)
Reopen at last positionNo (without config)Yes (with viminfo)
Speed on large filesSlow on files >10 MBFast even on files >100 MB

nano wins on immediate accessibility: you open, edit, save, and exit without needing to consult a manual. vim wins on productivity once you master the shortcuts — operations like “replace string X with Y in the next 50 lines” or “delete everything inside these quotes” become two-key combinations.

Installation and basic setup

Before comparing usage, make sure both are installed on your VPS so you can test them.

01

Update the package index:

sudo apt update

This command reads the repositories in /etc/apt/sources.list and downloads the updated metadata — required before installing any new package.

02

Install nano (if it isn’t already installed) and full vim:

sudo apt install -y nano vim

The vim package automatically replaces vim-tiny and enables syntax highlighting, visual mode, and macro recording. Confirm with vim —version | head -1 — you should see “Vi IMproved” and version 9.x or higher.

03

Set the system default editor (used by commands like crontab -e, git commit, visudo):

sudo update-alternatives --config editor

Choose the number matching your preference. To set it only for your user, add export EDITOR=nano (or vim) to your ~/.bashrc and run source ~/.bashrc.

nano — essential workflow

nano uses shortcuts visible in the footer of the screen. The ^ symbol means Ctrl, and M means Alt (Meta). The most commonly used commands:

04

Open a file for editing:

nano /etc/nginx/sites-available/default

If the file doesn’t exist, nano creates it on save. To open as root when the file requires permission (the case for /etc, /var, etc.), use sudo nano. Editing as a regular user and trying to save throws a permission error.

05

Edit the content normally. Use arrow keys to navigate, type to insert text, Backspace to delete. Essential shortcuts:

Ctrl+O    Save (Write Out) — confirm the filename with Enter
Ctrl+X    Exit — asks whether to save unsaved changes
Ctrl+W    Search text (Where) — Alt+W to find next
Ctrl+\    Replace — prompts for old and new text
Ctrl+K    Cut entire line
Ctrl+U    Paste cut line
Ctrl+G    Full help with all shortcuts

To select text, use Ctrl+^ (Ctrl+Shift+6) to mark the start, then move with arrow keys — Ctrl+K cuts the selection.

06

Save with Ctrl+O, confirm the name with Enter, and exit with Ctrl+X. If there are unsaved changes, nano asks “Save modified buffer?” — answer Y to save or N to discard.

Nano with syntax highlighting and line numbers

Edit ~/.nanorc and add: set linenumbers, set autoindent, set tabsize 2, include /usr/share/nano/*.nanorc. This enables line numbering, automatic indentation, 2-space tabs, and syntax highlighting for all supported languages.

vim — essential workflow

vim is modal: you don’t type directly into the file until you enter insert mode. This is the biggest source of confusion for beginners.

07

Open a file:

vim /etc/ssh/sshd_config

You enter normal mode — any letter typed becomes a command, not text. To insert content, press i (insert).

08

Learn the 4 basic modes:

Esc         Return to normal mode (always start here when in doubt)
i           Insert — type text at the cursor position
a           Append — type text after the cursor
o           Open — create a new line below and enter insert mode
v           Visual — select text (use arrow keys to expand)
:           Command-line — enter commands (save, exit, search)

When you’re in insert mode, the footer shows — INSERT —. Without this, you’re in normal mode and every keystroke is a command.

09

Save and exit. The most critical commands:

:w          Save the file (write)
:q          Quit — fails if there are unsaved changes
:wq         Save and quit (the most-used combination)
:x          Same as :wq but only writes if there are changes
:q!         Force quit, discarding changes
ZZ          Same as :wq (in normal mode, without :)

Esc + :wq + Enter solves 90% of cases. :q! is the emergency exit when you don’t know what happened and want to discard everything.

10

Efficient editing — what makes vim powerful are the operator + motion combinations:

dd          Delete the entire line
dw          Delete from position to the end of the word
d$          Delete to the end of the line
yy          Copy (yank) the line
p           Paste after the cursor
u           Undo
Ctrl+R      Redo
/text       Search for "text" (n next, N previous)
:%s/a/b/g   Replace "a" with "b" throughout the file
gg          Go to the first line
G           Go to the last line
:42         Go to line 42

The vim rule: command + motion. d3w deletes 3 words. y$ copies to the end of the line. These compound patterns are what save time on large files.

Editing system files without a backup

Before editing critical files like /etc/ssh/sshd_config or /etc/fstab, make a backup: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak. If the configuration breaks, you restore the backup and avoid losing access to the VPS. This is especially true for SSH — wrong config + reboot = inaccessible server.

When to use nano vs vim

There’s no “better” — there’s better for the context. Practical criteria:

Use nano when:

  • The task is editing 1-3 lines in a config file
  • You’ll only touch the file once and won’t return for a while
  • You’re on a server you rarely access
  • You want to avoid the risk of making a mode-related mistake and corrupting the file
  • You’re pasting snippets from tutorials without needing to format them

Use vim when:

  • You edit files frequently (daily admin work)
  • You work with large files (logs, SQL dumps, long configs)
  • You need to do bulk edits (regex replacement on every line)
  • You already use vim on your desktop and want consistency
  • The server doesn’t have nano (some Alpine containers only ship vi/vim)

A common pattern: use nano for the first few months of VPS admin, and migrate to vim when nano starts feeling slow for repetitive operations. There’s no shame in staying with nano — many experienced people prefer it for simplicity.

Verification

To confirm your setup is ready, test both editors on a test file:

echo "line 1" > ~/test.txt
nano ~/test.txt
# Add a line, save with Ctrl+O, exit with Ctrl+X
cat ~/test.txt
# Should show 2 lines

vim ~/test.txt
# Press i, add a line, Esc, :wq, Enter
cat ~/test.txt
# Should show 3 lines

rm ~/test.txt

If both worked and you were able to save and exit each one, your VPS is ready for daily administration.

Troubleshooting

”command not found: vim”

Your VPS image may only have vi (Busybox version) or neither. Run sudo apt install vim to fix it. On RHEL-like systems (AlmaLinux, Rocky), use sudo dnf install vim-enhanced.

File is “read-only” in vim

You opened it without sudo and the file requires privileges. Without losing your work, save it with :w !sudo tee % > /dev/null — this command passes the buffer content to tee running with sudo, writing to the file. Then exit with :q!.

Nano ignores indentation when pasting code

nano auto-indents each pasted line if autoindent is active, turning indented code into a staircase. Before pasting, press Alt+I to temporarily disable auto-indent. Paste the code, then re-enable with Alt+I again.

vim shows weird characters like ^M at the end of lines

The file was saved with Windows line endings (CRLF). Convert it with :set fileformat=unix followed by :w, or run dos2unix file.txt in the terminal before opening.

Next steps

With your editor chosen and the basic commands in your head, these are the topics that typically come next in VPS administration:

  1. Set up SSH key-based authentication — eliminate the login password
  2. Configure the UFW firewall to close unnecessary ports
  3. Automate config backups in /etc with rsync and cron
  4. Use git to version critical configuration files
  5. Learn tmux or screen to keep persistent SSH sessions

If you’re setting up a VPS for production and want infrastructure that delivers what it promises, a Hostini VPS ships with clean Ubuntu and Debian images (with nano and vim available), full root access, and a KVM console via the panel in case you make a configuration mistake and lose SSH.

Frequently asked questions

Which editor comes pre-installed by default on Ubuntu and Debian VPS?

Both nano and vim typically come pre-installed on modern Ubuntu and Debian, but vim usually ships in the minimal version (vim-tiny) without syntax highlighting. To get the full version, run sudo apt install vim. On minimal cloud images, sometimes only nano is present — it's worth checking with which nano and which vim before assuming.

How do I exit vim without saving? I'm stuck in the editor.

Press Esc to make sure you're in normal mode, then type :q! and Enter. The exclamation mark forces the exit, discarding changes. If you want to save before quitting, use :wq (write + quit). This is the most classic problem of those who open vim by accident — knowing how to exit before learning how to edit.

Can I configure nano to show line numbers and syntax highlighting?

Yes. Edit ~/.nanorc and add set linenumbers and set autoindent. For syntax highlighting, nano already ships with definitions in /usr/share/nano/ — just include them with include /usr/share/nano/*.nanorc in your .nanorc. It's not as powerful as vim, but it covers common cases (bash, yaml, nginx, json).

vim freezes with Ctrl+S in the terminal. How do I unfreeze it?

Ctrl+S is the terminal's XOFF shortcut — it pauses the output and makes it look like vim has frozen. Press Ctrl+Q to resume (XON). To avoid the issue, disable flow control by adding stty -ixon to your ~/.bashrc — this frees Ctrl+S for vim to use as a save shortcut (if you configure the mapping).

What's the difference between vim and vi?

vi is the original Unix editor; vim (Vi IMproved) is the modern reimplementation with extra features: multiple windows, syntax highlighting, unlimited undo, plugins. On modern Linux distributions, vi is usually a symlink to vim. On older systems or minimal containers, vi may be a limited Busybox version without these features.

How do I copy and paste text between the terminal and nano/vim without messing up indentation?

In nano, enable paste mode with Alt+X before pasting (or disable auto-indent with Esc+I). In vim, enter paste mode with :set paste before pasting and disable it with :set nopaste afterward. Without this, the editor's auto-indent stacks tabs/spaces on each pasted line, turning indented code into a staircase.

Topics:
Next steps Ryzen cloud with NVMe storage and always-on DDoS protection.Go live on a Hostini VPS →
Was this tutorial helpful?
Chat on WhatsApp