Sooner or later you must change a file on a machine that has no graphical editor—a server over SSH, a container, a rescue shell. Two editors are almost always installed: nano, which is friendly and obvious, and vim, which is powerful and everywhere. This lesson gets you productive in nano and, crucially, teaches you how to survive (and exit!) vim.
Open or create a file:
nano notes.txt
nano /etc/hosts # add sudo if the file is root-ownednano works like a plain notepad: type to insert, arrows to move. The shortcuts listed along the bottom use ^ for Ctrl:
That is genuinely all you need. For quick config edits on a server, nano is a perfectly professional choice.
vim (Vi IMproved) has a steeper curve because it is a modal editor: keys mean different things depending on the mode you are in. The payoff is that editing becomes a language—"delete 3 words" is d3w—and your hands never leave the home row. Even if you stay a nano person, you must know vim basics because vi is the only editor guaranteed on minimal systems, and some tools (like git or visudo) may drop you into it.
vim notes.txtvim opens in Normal mode, where letters are commands, not text. The five things everyone must know:
If the editor ever seems possessed—text not appearing, beeps, strange jumps—press Esc a couple of times and you are back in known territory.
Once the survival kit feels comfortable, these commands start paying rent:
h j k l move left / down / up / right (arrows also work)
w b jump forward / back one word
0 $ start / end of line
gg G top / bottom of file
dd delete (cut) the current line
yy yank (copy) the current line
p paste below the cursor
u undo Ctrl+r redo
/error search forward; n = next match
x delete the character under the cursorCommands compose: d$ deletes to end of line, 5dd deletes five lines, y3w copies three words.
:%s/localhost/127.0.0.1/g replace in the whole file
:s/foo/bar/ replace first match on this line
:%s/tmp/temp/gc g = all matches, c = confirm eachSet your preferred editor for tools that ask: export EDITOR=nano (in .bashrc, covered in lesson 12).
nano practice.txt # type a few lines, Ctrl+O, Enter, Ctrl+X
vim practice.txt # press i, add a line, Esc, then :wq
vimtutor # vim built-in 30-minute interactive coursevimtutor is the single best way to learn vim—it is an actual file you edit as you read it.
:wq to save-quit, :q! to bail out.dd, yy, p, u, /search.Next lesson: Process Management: ps, top, kill — see and control what is running.