Command Palette

Search for a command to run...

Hectal
PHASE 1Beginner ~7 min· topic 6 of 7

Topic 1.6

Editing Files on a Server: nano and vim Survival

In one line

Servers rarely have a graphical editor. nano is the friendly option; vim is everywhere, including minimal images and recovery shells. Learn enough vim to open, edit, save, and, most importantly, quit.

0/7 · 0%

Think of it like this

Vim is like a typewriter with two modes. In one mode your keys MOVE and COMMAND the page (delete a line, jump to the end); in the other they TYPE letters. Most vim confusion is simply being in the wrong mode.

Key ideas

  1. 01

    NANO: nano file.conf, type normally, Ctrl+O then Enter to save, Ctrl+X to exit, Ctrl+W to search. The shortcuts are listed at the bottom of the screen. Perfect for quick config edits.

  2. 02

    VIM MODES: NORMAL mode (the default; keys are commands), INSERT mode (typing text; enter with i, leave with Esc), and COMMAND-LINE mode (: then a command). Saving and quitting: :w save, :q quit, :wq save and quit, :q! quit WITHOUT saving (the famous escape hatch).

  3. 03

    Normal-mode essentials: h j k l or arrows to move, gg/G top/bottom, /text then n to search, dd delete a line, yy copy a line, p paste, u undo, Ctrl+r redo, :%s/old/new/g replace everywhere, :set number show line numbers.

  4. 04

    Safety habits: sudoedit /etc/nginx/nginx.conf (or sudo -e) edits a copy with your own editor settings and writes it back as root, safer than sudo vim. Validate configs before reloading (nginx -t, sshd -t, visudo -c). Set your default editor with export EDITOR=vim (used by git commit, crontab -e, visudo).

Code & diagrams

the vim you actually needtext
vim /etc/myapp/app.conf
  /listen        search for "listen", n = next match
  i              start typing (INSERT mode)
  Esc            back to NORMAL mode
  dd  u          delete line, undo
  :%s/8080/9090/g   replace everywhere
  :wq            save and quit      :q!  quit without saving

Explain it without notes

01

You opened vim, typed some text and now nothing works as expected. What happened and how do you get out safely?

Practice

01

Using vim only, change the port in a config file from 8080 to 9090 on every line, show line numbers, and save.

Done when you can

  • I can edit, save, and quit in both nano and vim

  • I use sudoedit and validate configs before reloading