You can finally quit it!
So I tried to get the hold of Vim once upon a time, when I was taller, younger and sharper.
It was probably some cold windy midnight of the late December of 2016. I opened up my vault, picked up my black hoodie with the Linux Penguin on it and put it on. Then I turned off all the lights of my room and locked it up from the inside.
Only the black-shadowy light from my terminal’s light green font was illuminating my room. With this 10x hacker environment, and of course without even thinking of further consequences, as I always do, I opened up my terminal and simply wrote **vim**
and hit enter.
And the rest is a story of nightmares.
Okay I am exaggerating a lot here. 😛
Recently, when I was asked by the boss at the office to learn Vim (as I had to navigate through an **ssh**
server), I decided to finish my unfinished business with Vim.
Which brought me here on Medium, to write about Vim. As a wise man once posted on Facebook, sharing knowledge is power.
So, open up your terminal and let’s talk about it.
I am assuming you have **bash**
and you are a Linux user. I hope there are similar ways for Windows users to install Vim.
**sudo apt-get update**
.**sudo apt-get install vim**
. That’s it.This is going to be fun!
**vim mytext.txt**
on terminal and hit enter.**vimrc**
. That’s why it will probably look different from your terminal. You can find **vimrc**
here. For now I guess you should ignore it.
Vim!
Just write **:wq**
and hit enter.
What it does is, it writes the file on your disk and saves all the changes you made, and quits. If you do not want to save the changes, hit **:q!**
.
Yep, that’s it!
So now we will actually write something on Vim.
**i**
from Normal Mode.
Poem from Reddit.
**ESC**
to switch to Normal Mode. And type **:w**
. Or you can also write **:wq**
to write and quit.
When you are in Normal Mode, to move up-down-left-right, you should use:**h**
— left**j**
— down**k**
— up**l**
— rightYeah this is so weird. But it is meant for convenience. I guess once you are very accustomed to the key bindings of Vim, you can realize that.
**A**
with **<shift>**
key.
Let’s assume we want to edit our previous text file. Say, you want to replace the word gray with blue.To do this, of course you can go the Insert Mode and use backspace to remove and write whatever you want_._ But we can do it more smoothly in Normal Mode. Move your cursor to the beginning of the word you want to delete, and hit **dw**
.
**dd**
.
Poem by M Chowdhury (1995 — )
**:d$**
which deletes from the position of the cursor to the end of the line.**u**
. To redo, hit **CTRL-R**
.**rx**
where x is the character you want the current character to be replaced with.**x**
.I guess this is it for the part 1. I hope to get the next part done very soon! Hope you learned something new. Now go and show it off to your girlfriend.
Thanks!
For part 2: Lets learn Vim! Part 2