Oh.. Vim, some people love it, most people hate it. Just the idea of having to modify a simple file in Vim makes some people dizzy. Having to learn all the keyboard commands and not seeing any buttons that you can click with your mouse in a program from 80’s is already an ugly presentation. I remember the first day at the new company in Spain my coworkers asking me what I’m using to program, and I answered: Vim. You should have seen their reaction to that! I admit the path to using Vim as a default IDE, (yes IDE!) wasn’t so pleasant at the begging, but with some practice, you’ll understand why some people love it. So this is the first post of Vim-series where I’ll show you 5 most essential commands to kick-start your journey in Vim or just to edit some files on the fly.
1. hjkl: Moving around the file
This is the first command you will need to move around your file, these four letters are positioned on your home row, under your right hand. And they represent:
h: Move the cursor left j: Move the cursor down k: Move the cursor up l: Move the cursor right
2. gg and G: Jump to start or end of file
If you find your self in file with hundreds of lines, using ‘j’ or ‘k’ keys to get to the end of the file would be painful. So we use ‘gg’ and ‘G’ keys to jump up and down the file, so:
gg: Double pressing g key will move the cursor the start of the file G: Capital G (Shift + g) will move the cursor to the end of the file
3. i: Insert text
After you move the cursor to the desired position in the file, editing text is possible after entering the ‘Insert mode’ by pressing the ‘i’ key. After editing the text press ‘ESC’ and return to ‘Normal mode’.
1. Press 'i' key and start editing 2. Press 'ESC' when finished
4. w: Saving a file
To save your file changes is simple, it’s a 2-step process:
1. Enter the command mode by pressing ":" (Shif+;) 2. Press the 'w' key, which stands for write
5. q: Quit Vim
Now that last and most famous command you will ever need is quit command. Again it’s a 2-step process where we will need to enter in command mode:
1. Enter the command mode by pressing ":" (Shif+;) 2. Press the 'q' key, which stands for quit and has exited Vim
I know you like easter-eggs, so here is one for you:
1. Enter the command mode by pressing ":" (Shif+;) 2. Type 'smile' and press 'Enter'
Learning Vim is a life-long process, you always learn something new but you need to know just a few commands to do your daily tasks efficiently. If your are serius about more in-depth learning, I highly recommend Pracitcal Vim book by Drew Neil.
Bojan Vidanovic is a computer programmer, specialized in front-end web development. Love making internet products, blogging, learning, reading, calisthenics and fitness enthusiast.