Vim basic CheatSheet for beginners

Dharan
3 min readAug 18, 2019

--

Most of the people tired off using Vim, and I do faced the same problem. But, in the actual case, it’s not a big deal. The thing is, we should understand the basics to use that.

First, Launch your fellow terminal then,

Open any file , that you wanted to edit . In my case -I’m opening main1.java by using the below command

vi main1.java | vim main1.javaNote that we are in Command Mode now

To edit the file or to insert any characters in that file, we need to get into- “INSERT mode” by pressing the

"i" button on your keyboard

Now, edit whatever u need to, by moving the cursor forward and backward by using your arrow keys, and deleting the contents using your backspace key

Now, its time for saving the contents…nooo don’t use ctrl+s -that fellow won’t work here.., Here its about what mode we are in -Now, we are in the INSERT mode-So, we have to get into command mode to make our command to work, For that, press

"esc" button for switching back to command mode 
Then colon , then press "w" and "Enter" for Save (write)
Inshort:
(esc):w(Enter)
(esc):wq(Enter)
[Save and close]

Now It’s time to exit, right? then press

"esc" button for switching back to command mode 
Then colon , then press "q" and "Enter" for Save (write)
Inshort:
(esc):q(Enter)
[ It will warn you to save the unsaved content changes , and won't let you to exit sometimes ]
(esc):q!(Enter)
[ It won't warn you to overlook the unsaved changes]

To copy and to paste the things inside the terminal, we use a different terms -which is “yank” and paste. Note that “yank” will copy the contents to the terminal’s own clipboard -it won’t let you copy outside ( for copying it to the system’s clipboard — read about +clipboard )

For yank, go to “VISUAL LINE Mode” by pressing the

Shift+V on your keyboard

So, that we shall notice terminal showing us the term “visual mode” in its bottom. Now just simply drag the mouse or use down arrow to select mulitple lines inorder to do some operations. Now , yank by pressing the

"y" button on your keyboard (Visual mode)

To delete , just press

"d" button (Visual mode)

To paste it somewhere on the same or on the other page, press the

"p" button (Command mode)

Some Shortcuts will make this process cool. They are

"gg" to go to First Line
"Shift + G" for the Last Line
Sometimes these two comes handy when we were selecting the full file for the process of "yank" in the visual mode..
Haha Just try for it!!
/for to search the term "for"
:34 to get into line 34
:w for the word traversal forward
:b for the word traversal backward

Now let’s move on to vimdiff , with the following command to compare the files where we use this more often to resolve the merge conflict.

vimdiff main1.java main2.java
vimdiff workspace

From the above pic, it is sure that we can easily find out the differences between the files , pink spots are for the modified area, and the blue is for the missed out lines ( either removed or added)

Shortcuts to access this window

Ctrl + w Ctrl + w ( 2 times ) to switch between the files (window)[c  (Previous change)
]c (Next change)

Now, to resolve the change conflicts -just move the cursor where you wanted to change and use

:diffget (which will just move the contents on the specific line on the other window to the current window) :diffput (just do the opposite - moves the content from the current wnidow to the other)

ie.,
If the cursor is on the line where the pink highlights are depicted on the first window for instance,

on this line → int temp = arr[i] and if i use :diffget there, then those lines are commented as if they were in the second window….yesss that’s it!!Shortcuts 
:dg
(for diffget)
:dp
(for diffput)

For your convenience, better use simple “yank” and paste as I told earlier. And at last, don’t forget to save and close which is

(esc) :wq (enter)

And there are still many features available in the vim, but what I told now is more enough to manage the files in the vim…

Have a nice day!!

--

--

Dharan

Professional Software engineer | Trinet Zenefits | Ex-Zoho | KCT Alumni | Music - Code - Travel