Skip to content
DevOps devops linux 6 min read

Text Editors: Nano & Vim

Sooner or later you will need to edit a file on a Linux server. There is no point-and-click app like Notepad — instead you edit files right inside the terminal (the text-based window where you type commands). The two editors you will meet everywhere are nano (a text editor that is simple and shows you the shortcuts on screen) and vim (a powerful text editor that is installed on practically every Linux machine on earth). This page teaches enough of both to be productive on Ubuntu 22.04 / 24.04 LTS today.

Why you need a terminal editor

When you log into a remote server over SSH (Secure Shell — a way to control another computer over the network from your own terminal), you usually have no graphical desktop. The only way to change a config file like /etc/nginx/sites-available/default or /etc/ssh/sshd_config is to open it in a terminal editor, make your change, and save. Knowing at least one editor is not optional for DevOps work — it is a daily task.

There are two main choices, and they suit different moments:

EditorBest forLearning curveWhere it lives
nanoQuick edits, beginners, copy-paste a configAlmost none/usr/bin/nano (preinstalled on Ubuntu)
vimPower editing, scripting, any serverSteep at first/usr/bin/vim (on every Unix box)

Recommendation: Start with nano so you are never stuck. But learn the vim basics below, because some minimal servers and containers only ship with vi/vim and no nano at all. Knowing how to save and quit vim has rescued countless engineers.

Nano: the friendly editor

Nano is the easiest editor to learn because it prints its shortcuts along the bottom of the screen. The ^ symbol you see there means the Ctrl key. So ^O means “press Ctrl and O together”.

Opening and editing a file

To open (or create) a file, just type nano followed by the filename. Editing a system file needs sudo (run a command as the administrator/root user):

sudo nano /etc/hosts

Once open, you simply type. Arrow keys move the cursor, Backspace deletes — it behaves like a basic text box.

Saving and exiting

These are the two shortcuts you must remember:

  • Ctrl+O — “write Out” (save). Press it, then press Enter to confirm the filename.
  • Ctrl+X — exit nano. If you have unsaved changes it asks “Save modified buffer?”; press Y then Enter to save, or N to discard.

A few more handy nano shortcuts:

ShortcutWhat it does
Ctrl+OSave the file
Ctrl+XQuit
Ctrl+WSearch (“Where is”)
Ctrl+KCut the current line
Ctrl+UPaste (uncut) the line
Ctrl+_Go to a line number
Ctrl+GOpen the help screen

When to use nano: quick one-off edits, pasting a config block someone gave you, or any time you do not want to think. When not to: large refactors or repetitive edits where vim’s commands are far faster.

Vim: powerful and everywhere

Vim feels strange at first because it has modes. A mode is a state that changes what your keystrokes do. The big surprise for beginners is that you cannot just start typing — you have to enter the right mode first.

The three modes you need:

  • Normal mode — where you land when vim opens. Keys are commands (move, delete, copy), not text. Press Esc to return here from any other mode.
  • Insert mode — where you actually type text. Enter it by pressing i.
  • Command-line mode — for saving, quitting, and searching. Enter it by pressing : (colon) from normal mode.

Opening a file

sudo vim /etc/ssh/sshd_config

When it opens you are in normal mode. To type, press i (insert). When done typing, press Esc to go back to normal mode.

Saving and quitting

From normal mode, press : then type one of these and hit Enter:

CommandWhat it does
:wWrite (save) the file
:qQuit
:wqSave and quit (the one you will use most)
:xSave and quit (same as :wq)
:q!Quit and throw away all changes
:w !sudo tee %Save a file you opened without sudo (handy escape hatch)

The classic gotcha: if you ever feel trapped in vim, press Esc first (to guarantee you are in normal mode), then type :q! and Enter to quit without saving. That sequence always works.

Essential editing keys

These all run in normal mode. They are fast once they become muscle memory:

KeyAction
iInsert before the cursor
aInsert after the cursor
oOpen a new line below and insert
ddDelete (cut) the whole current line
yyYank (copy) the current line
pPaste below the cursor
uUndo
Ctrl+rRedo
ggJump to the top of the file
GJump to the bottom of the file
/wordSearch forward for “word” — press n for next match
:set numberShow line numbers

A typical edit looks like this: press i, type your change, press Esc, then :wq and Enter.

Searching text

In normal mode, type / followed by what you are looking for and press Enter:

/PermitRootLogin

Vim jumps to the first match. Press n for the next match, N for the previous one. This is great for finding a setting buried deep in a long config file.

A quick comparison

Questionnanovim
Easy to learn?Yes, shortcuts shown on screenNo, needs practice
Has modes?NoYes (normal / insert / command)
Save and quitCtrl+O, then Ctrl+X:wq
On every server?Usually, but not guaranteedYes (or vi)
Fast for big edits?NoYes

Best Practices

  • Always edit system files with sudo — without it you cannot save and you waste your edits. If you forget, use :w !sudo tee % in vim to recover.
  • Back up before risky edits: sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak so you can roll back.
  • Validate config after editing rather than restarting blindly — e.g. sudo nginx -t or sudo sshd -t to catch syntax errors before they break a service.
  • Learn vim’s :q! escape so you are never stuck in an editor on an unfamiliar box.
  • Pick one editor and get fluent — nano is plenty for most DevOps tasks; add vim once you find yourself making the same edit over and over.
  • Avoid editing files while a deploy is running to prevent half-written configs being picked up by a restart.
Last updated June 15, 2026
Was this helpful?