Chapter 3: Linux Basic Commands
3.10 Text editors: nano and vim
nano — easiest for beginners
sudo nano /etc/nginx/nginx.conf
Shortcuts are shown at the bottom (^ means Ctrl): Ctrl+O then Enter = save, Ctrl+X = exit, Ctrl+W = search, Ctrl+K = cut line, Ctrl+U = paste.
vim — available everywhere
Vim has modes: Normal (for commands, the default), Insert (for typing) and Command-line (after :).
| Keys | Action |
|---|---|
i |
Enter insert mode (start typing) |
Esc |
Back to normal mode |
:w |
Save |
:q |
Quit (:q! quit without saving) |
:wq or ZZ |
Save and quit |
dd / yy / p |
Delete (cut) line / copy line / paste |
u / Ctrl+R |
Undo / redo |
/text then n |
Search forward, next match |
:set number |
Show line numbers |
gg / G |
Go to first / last line |
:%s/old/new/g |
Replace all |
Stuck in vim?
Press Esc two times, then type :q! and press Enter. You are out without saving.