Editors: nano and vim

K
Kai··4 min read

A Linux server usually has no graphical interface. When you need to edit a config file, you use an editor that runs right in the terminal. This article teaches the two most common ones: nano (easy for beginners) and vim (present almost everywhere). Knowing at least one is mandatory.

Installation

Minimal Ubuntu usually has no editor preinstalled. Install one (package management in Article 11):

apt-get update && apt-get install -y nano vim

Almost every Linux server always has vi available (the original version; vim is the enhanced one). That's why knowing vim/vi is a "lifesaver" skill — even when nothing extra is installed, you can still edit files.

nano: simple, good for beginners

Open (or create) a file:

nano notes.txt

You type text directly like any normal editor. At the bottom of the screen is a list of shortcuts, where ^ means the Ctrl key:

  • Ctrl + O then Enter — save (Write Out).
  • Ctrl + X — quit (if unsaved, nano asks).
  • Ctrl + W — search.
  • Ctrl + K — cut a line; Ctrl + U — paste.
  • Ctrl + G — help.

nano is intuitive because the key hints are always shown. For a beginner, using nano for quick edits is enough.

vim: why you should know it, even though it's harder

vim is powerful and everywhere, but it has a "steep entry" because it works in modes — this is what confuses beginners most (you type and the screen jumps around, or you can't get out).

        ┌──────────────┐
   i,a  │              │  Esc
  ┌────►│  Insert mode │────┐   type text here
  │     │  (insert)    │    │
  │     └──────────────┘    │
┌─┴────────────┐            ▼
│ Normal mode  │◄───────────┘
│ (move around,│
│  key cmds)   │── when you open a file you're here
└─┬────────────┘
  │ type :
  ▼
┌────────────────────────┐
│ Command-line mode      │  :w save  :q quit  :wq save+quit  :q! discard
└────────────────────────┘

When you open a file, vim is in Normal mode — the keys are commands, not for typing text. This is where beginners tend to panic.

Survival vim: the minimum to remember

Open a file:

vim config.txt
  1. Insert text: press i (insert) to enter Insert mode, now type normally.
  2. Leave Insert mode: press Esc to return to Normal mode.
  3. Save and quit: in Normal mode, type :wq then Enter (w = write, q = quit).
  4. Quit without saving: type :q! then Enter (the ! = force, discard changes).

Just those four steps are enough to open, edit, save, and quit. "How do I quit vim" is the most famous question — the answer: press Esc then type :q!.

A few more useful commands (in Normal mode)

  • Move around: arrow keys, or h j k l (left/down/up/right).
  • dd — delete a whole line. yy — copy a line. p — paste.
  • u — undo. Ctrl + r — redo.
  • /keyword then Enter — search; n to go to the next match.
  • :set number — show line numbers.
  • gg to the top of the file, G to the bottom.

You don't need to memorize all of it right away. Remember "survival vim" (i, Esc, :wq, :q!) first, and pick up the rest as you go.

Verify vim really works (without entering the interface): vim can run commands in ex mode. For example, replace text then save in a single line — vim -e -s file takes the commands :%s/old/new/ and :wq. The :%s/old/new/ syntax (replace across the whole file) also works while you have a file open normally.

Which one to choose

  • New to it, need a quick edit: use nano, the key hints are shown so you won't get lost.
  • Working across many servers, want to be sure there's always an editor: learn vim (because vi is always available). Just the "survival" level is enough to get through any situation.

Practical advice: use nano for comfort, but you must remember how to quit vim — because there will be times you land in vim by accident (many commands open vim by default, like git commit with no message) and need to get out.

🧹 Cleanup

rm -f notes.txt config.txt

Wrap-up

On a server with no GUI, you edit files with a terminal editor. nano is simple, its shortcuts shown (Ctrl+O to save, Ctrl+X to quit) — good for beginners. vim is powerful and everywhere but mode-based: remember i to insert, Esc to leave, :wq to save and quit, :q! to discard. Knowing at least the survival level of vim is a lifesaver skill on a server.

Now you can create and edit files. Article 5 teaches how to read and process file content at scale — cat, grep, sed, awk and friends — the tools that make the Linux command line powerful.