Vim Survival Guide: How to Exit and Eventually Thrive
Step 1: How to Exit Vim
It is a running joke in the developer community, but getting stuck in Vim on a remote server is a rite of passage. If you are currently trapped, press the Esc key to ensure you are in Normal Mode, type :q!, and press Enter to quit without saving. To save and quit, type :wq.
The Philosophy of Modes
Vim is a "modal" text editor. Unlike VS Code or Notepad where typing always inserts text, Vim has different modes. Normal Mode is for navigating and deleting. Insert Mode is for typing. Visual Mode is for selecting text.
Essential Navigation (Normal Mode)
Forget the arrow keys. Keep your hands on the home row.
h- Move Leftj- Move Downk- Move Upl- Move Rightw- Jump forward to the start of the next word.b- Jump backward to the start of the previous word.gg- Jump instantly to the very top of the file.G- Jump instantly to the very bottom of the file.
The Magic of Verbs and Nouns
Vim commands are like a language. You combine a "verb" (action) with a "noun" (motion). For example, d is delete. w is word. Therefore, dw deletes a word. d$ deletes everything from the cursor to the end of the line.
ci" - Change Inside Quotes. (Deletes everything inside the nearest quotes and puts you in Insert Mode).
dd - Delete the entire current line.
u - Undo your last mistake.
Ctrl + r - Redo.Once your brain maps these commands to muscle memory, you will edit code faster than you ever thought possible without ever touching your mouse.