2.2 Text Editing with Vim
Why Vim? It is installed on almost every Unix-like system by default. In a rescue shell, you might not have nano or code, but you will have vi or vim.
The Modes
Section titled “The Modes”Vim is “modal”. Keys do different things depending on the mode.
- Normal Mode: The default. Keys are commands (navigation, copy/paste). Press
Escto return here. - Insert Mode: For typing text. Press
ito enter. - Command (Ex) Mode: For saving/quitting. Press
:to enter.
Cheat Sheet
Section titled “Cheat Sheet”1. Opening and Quitting
Section titled “1. Opening and Quitting”vim file.txt: Open file.:w: Write (Save).:q: Quit.:wq: Save and Quit.:q!: Quit without saving (discard changes).
2. Basic Editing
Section titled “2. Basic Editing”i: Switch to Insert Mode (start typing).Esc: Go back to Normal Mode.
3. Navigation (Normal Mode)
Section titled “3. Navigation (Normal Mode)”hjkl: Left, Down, Up, Right (arrow keys also work).gg: Go to start of file.G: Go to end of file./pattern: Search for “pattern”. (nfor next match).
4. Direct Actions (Normal Mode)
Section titled “4. Direct Actions (Normal Mode)”dd: Delete (cut) current line.yy: Yank (copy) current line.p: Paste below.u: Undo.Ctrl + r: Redo.