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.
Editing
- i đ start editing at the current position
- a đ same but moves the carret to the next char
Exiting
- 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
Searching
- /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
Undoing
- u đ Undo
- Ctrl + r đ Redo
Moving
- 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 đ