Vim Survival Toolkit
I used to hate Vim.
Back when I was in CS school, teachers took great pleasure in forcing us to use this dinosaur tool that you can only despise after 5 minutes of use. But nowadays I can thank my teachers for getting all this knowledge into my head.
Indeed, you don't always have the opportunity to have an Atom, a VSCode or a PHPStorm to edit a file. Sometimes, you have to log in with SSH on a production server to remove a "," from a configuration file that is currently rendering the said server unusable. And then the ony editor at your disposal might be Vim.
There are people who use Vim as an IDE, but I'm not among them. Instead, I have a basic knowledge of it that allows me to do only the very necessary and most simple stuff. Editing, moving around, saving, and most importantly when it comes to Vim: quitting.
The commands below are, in my humble opinion, the only essential commands you need to know in order to survive with Vim.
- i 👉 start editing at the current position
- a 👉 same but moves the carret to the next char
- ESC 👉 gets you back in "command" mode and stops edition of the file
- :q↩️ 👉 quit
- :q!↩️ 👉 quit even if changes were made
- ZZ↩️ 👉 save and quit
- /something↩️ 👉 Finds "something" in the file and moves the carret to the first found occurrence
- n 👉 Finds the next occurrence of the word you searched for and moves the carret to it
- N 👉 Previous
- u 👉 Undo
- Ctrl + r 👉 Redo
- G 👉 Go to the end of the file
- gg 👉 Go back to the start of the file
Playing with lines
- o 👉 Insert a new line below the carret
- O 👉 Insert new line above the carret
- dd 👉 Remove the current line
- 5dd 👉 Remove 5 lines starting from the current line (but you can enter any number you want)
These commands have allowed multiple production servers to be saved over the last 15 years 😁
Originally posted as a thread on Twitter.