DEV Community

Quentin Delcourt
Quentin Delcourt

Posted on • Originally published at quentin.delcourt.be

Vim Survival Toolkit

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)

Collapse
 
karthiknayak98 profile image
KarthikNayak

Instead if '1G' you can use 'gg' to go back to first line.

Collapse
 
kant312 profile image
Quentin Delcourt

Ha! I didn't know that, it's indeed a lot easier, I'll replace it in the post. Thanks!

Collapse
 
terceranexus6 profile image
Paula

I love this, I have my mechanical keyboard customized for vim and I always look for this kind of awesome cheat-sheets. Thanks!

Collapse
 
kant312 profile image
Quentin Delcourt

Cool! Glad it helps :)
I'm curious about the keyboard: how did you do the customisation?

Collapse
 
terceranexus6 profile image
Paula

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.

Thread Thread
 
kant312 profile image
Quentin Delcourt

Beautiful! Thanks for sharing. One day, I'll get one of those πŸ™‚

Collapse
 
yvesnrb profile image
yvesnrb • Edited

Also very useful is 'A' - append to the end of the line.