TL;DR Skip to the commands.
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 π
Top comments (7)
Instead if '1G' you can use 'gg' to go back to first line.
Ha! I didn't know that, it's indeed a lot easier, I'll replace it in the post. Thanks!
I love this, I have my mechanical keyboard customized for vim and I always look for this kind of awesome cheat-sheets. Thanks!
Cool! Glad it helps :)
I'm curious about the keyboard: how did you do the customisation?
I just chose different colours for the keys more used like hjkl and scape. I want to change a few more, but still deciding the correct setup in a tiny keyboard.
Beautiful! Thanks for sharing. One day, I'll get one of those π
Also very useful is 'A' - append to the end of the line.