Getting Started with Text Editors: Vim and Nano Basics
Editing config files on your server starts with nano's save/exit shortcuts, then a grasp of vim's modes when you need it.
Once you're logged into your VPS or dedicated server, editing config files and writing scripts in the terminal is unavoidable. The two editors you'll meet everywhere on Linux are nano and vim: nano is simple and intuitive, great for beginners; vim is powerful but adds the hurdle of "modes." Start with nano, and pick up vim when you actually need it.
Nano: Ready Out of the Box
Nano keeps its shortcuts printed along the bottom of the screen, so there's little to memorize. Open a file:
nano /etc/nginx/nginx.conf
You can type right away and move around with the arrow keys, just like a plain text editor. The ^ symbol at the bottom stands for the Ctrl key. The shortcuts you'll use most:
- Ctrl+O — save (write out). Press it, then hit Enter to confirm the filename.
- Ctrl+X — exit. If you have unsaved changes, it asks first (Y to save, N to discard).
- Ctrl+W — search for text.
- Ctrl+K / Ctrl+U — cut / paste the current line.
Remember Ctrl+O to save and Ctrl+X to quit, and you're set for everyday work.
Vim: Understand the Modes First
Vim's learning curve comes almost entirely from its modes. When you open a file you're in normal mode, where keystrokes run commands rather than type text. Open a file:
vim config.yaml
The core workflow is just three steps:
- Press i to enter insert mode, where you can type normally.
- When you're done, press Esc to return to normal mode.
- Type :wq and press Enter to save and quit.
Other handy commands (all from normal mode):
- :q! — quit without saving (use it when you've made a mess and want to bail).
- :w — save without quitting.
- Move around: h left, j down, k up, l right — or just use the arrow keys.
- Delete: x removes one character, dd deletes a whole line.
- /keyword then Enter — search forward.
As long as you remember "i to start typing, Esc to stop, :wq to save and exit, :q! to bail out," you'll never be stuck inside vim.
Summary
Beginners should reach for nano first: Ctrl+O to save, Ctrl+X to exit, almost no learning curve, and enough for most config edits. When you need an editor that's preinstalled everywhere, or want to work faster, spend a little time learning vim's modes. Knowing a bit of both means no server can catch you off guard.