Skip to content

Text Editors — Nano and Vim


Every command so far has worked on whole files — copying them, moving them, deleting them — without ever looking inside one. Sooner or later you need to actually open a file and change what’s in it, and on a system with no graphical interface, that means a terminal-based text editor. This chapter covers two: nano, which you’ll use for the rest of this course, and vim, which you won’t use here but will absolutely encounter on someone else’s system.

Why Two Editors, And Why Both Matter

nano is straightforward — open it, type, save, done. Every available command is listed on screen the whole time, so there’s nothing to memorize just to get started.

vim is a different story. It’s powerful, fast once you know it, and installed by default on a huge share of Linux servers — but it behaves nothing like a typical editor, and opening it with zero preparation is a genuinely disorienting experience. The problem is that you don’t get to choose which editor is available on a system you’re troubleshooting at 2 AM. If nano isn’t installed and vim is the only option, you need enough to open a file, make a change, and get out safely.

nano: Straightforward Editing

Open a file with:

nano notes.txt

If notes.txt doesn’t exist yet, nano creates it the moment you save. You’ll see the file’s contents fill the terminal, with a menu of commands pinned along the bottom of the screen.

Typing works exactly as you’d expect — move the cursor with the arrow keys, type to insert text, use Backspace or Delete normally. The commands along the bottom use ^ to mean the Ctrl key, so ^O means Ctrl+O.

The handful you actually need:

ShortcutAction
Ctrl+OWrite out (save) the file
Ctrl+XExit
Ctrl+KCut the current line
Ctrl+UPaste the last cut line(s)
Ctrl+WSearch within the file

Saving and exiting is almost always the same two-step motion: Ctrl+O, then Enter to confirm the filename, then Ctrl+X to exit. If you try to exit with unsaved changes, nano asks first — one of the few commands in this course that does.

That’s genuinely most of what there is to know. nano’s entire design goal is to not require a dedicated lesson longer than this.

vim: Enough To Survive

vim’s defining trait — and the thing that catches people off guard — is that it has modes. What a keystroke does depends entirely on which mode you’re in, and unlike nano, vim doesn’t tell you what to press on screen.

Open a file the same way:

vim notes.txt

You’ll land in Normal mode. In this mode, letter keys aren’t inserted as text — they’re commands. This is the single most common source of confusion for anyone opening vim for the first time: typing feels like it’s “doing nothing,” when really it’s issuing commands you don’t recognize yet.

To actually type text, you need Insert mode:

  • Press i to enter Insert mode at the cursor.
  • Once you’re in Insert mode, typing works normally — it inserts text, just like nano.
  • Press Esc to leave Insert mode and return to Normal mode.

Everything else you need happens back in Normal mode, after pressing Esc:

Keystroke (Normal mode)Action
iEnter Insert mode
EscReturn to Normal mode
:w then EnterWrite out (save)
:q then EnterQuit (only works with no unsaved changes)
:wq then EnterSave and quit together
:q! then EnterQuit and discard changes, no confirmation

That : at the start of :w, :q, and :wq isn’t a typo — it drops you into a third mode, Command-line mode, where you type a short instruction and press Enter to run it.

Tip

If you only remember one thing about vim, remember this sequence: press Esc (to make sure you’re in Normal mode, no matter what mode you were actually in), then type :wq and press Enter. That gets you out safely, with your changes saved, from almost any state you can accidentally get into.

The Mode Model, Visually

    stateDiagram-v2
    [*] --> Normal
    Normal --> Insert: press i
    Insert --> Normal: press Esc
    Normal --> CommandLine: press &#58
    CommandLine --> Normal: Enter<br/>e.g. &#58w
    CommandLine --> [*]: Enter<br/>&#58q or &#58wq
  

This is the entire mental model vim is built on. Everything that feels confusing about it early on traces back to not knowing which of these three states you’re currently in.

If You Get Stuck In vim

This happens to everyone at least once: you’re typing, nothing looks right, and you’re not sure what mode you’re in or how to get out. The reliable escape sequence is:

Esc
:q!
Enter

Esc guarantees you’re in Normal mode regardless of what came before. :q! quits without saving, discarding whatever happened while you were stuck. You’ll lose any unsaved changes, but you’ll get back to your shell prompt — which, in an unfamiliar editor, is usually the better outcome than staying stuck.

Which One Should You Actually Use?

For every hands-on example in the rest of this course, we’ll use nano — it lets you focus on the concept being taught rather than the editor itself. But recognize vim on sight, know that i gets you typing and Esc then :wq gets you out safely, and you’ll never be stranded on a system that doesn’t have nano installed.

What’s Next

With a way to actually edit file contents in hand, the next chapter rounds out this section: viewing files without opening a full editor, and searching for both file names and text content across the filesystem.

Last updated on