Overview of Nano and Differences from Vi/Vim

1. No Modes

  • Unlike vi/vim, which has Normal mode and Insert mode, nano is always in Insert mode, meaning you can start typing immediately.
  • No need to switch between modes with ESC or i.

2. Command Execution

  • In vi/vim, commands are executed using : (e.g., :w, :q, :x).
  • In nano, all commands use the Ctrl (^) key, e.g., Ctrl + X to exit, Ctrl + O to save.

3. Text Selection and Copy/Paste

  • vi/vim uses Visual mode (v to start selecting, d or y to delete or copy).
  • nano uses Ctrl + 6 to start selecting, followed by Ctrl + K (cut) or Alt + 6 (copy).

Nano vs. Vi/Vim – Command Comparison

ActionNanoVi/Vim
Open a filenano filenamevi filename
ExitCtrl + X:q
SaveCtrl + OEnter:w
Save and ExitCtrl + OEnterCtrl + X:wq or ZZ
Force Exit (without saving)Ctrl + XN:q!
Move to beginning of lineCtrl + A0
Move to end of lineCtrl + E$
Move up one line or Ctrl + Pk
Move down one line or Ctrl + Nj
Page upCtrl + YCtrl + b
Page downCtrl + VCtrl + f
Move to a specific lineCtrl + _line number:line number
SearchCtrl + W/
Go to next matchAlt + Wn
ReplaceCtrl + \\:s/search/replace/g
Cut a lineCtrl + Kdd
Cut selected textCtrl + 6 (start selection) → Ctrl + Kvd
Copy selected textCtrl + 6 (start selection) → Alt + 6vy
PasteCtrl + Up
Show current line numberCtrl + CCtrl + g
Redraw screenCtrl + LCtrl + l
Open nano helpCtrl + G:help

Key Points for Vi/Vim Users Switching to Nano

  1. No modes, so you can type immediately.
    • No need to press i or ESC to switch modes.
    • In nano, you can start typing immediately after opening it, and there is no need for an equivalent operation to i
  2. Use Ctrl instead of : commands.
    • Ctrl + X (exit), Ctrl + O (save), Ctrl + K (cut).
  3. Text selection and copy/paste work differently.
    • Ctrl + 6 starts selection, Alt + 6 copies, Ctrl + K cuts.
  4. Search and replace use different commands.
    • Ctrl + W (search), Ctrl + \\ (replace).
  5. Nano is simpler but lacks advanced features like macros and plugins.
    • For basic file editing, nano is quicker and easier.
    • For complex text manipulation, vim is more powerful.

Useful Nano Options

OptionDescription
nano -cShow line numbers (:set number in Vim)
nano -mEnable mouse support (:set mouse=a)
nano -wDisable line wrapping (:set nowrap)
nano -lEnable syntax highlighting (syntax on)

Example: Open a file with line numbers

nano -c filename

Conclusion

  • Nano is lightweight and simple, great for quick edits.
  • Vi/Vim is more powerful for advanced text manipulation.
  • If you’re used to Vim, the main challenge in Nano is adapting to Ctrlbased commands.
  • For quick file edits, Nano is faster than Vim, but Vim is better for scripting and customization.

If you want nano to feel a bit more like vi, try using nano -c -m -w when opening files