DEV Community

Cover image for VIM is gem!!
Arun Krish
Arun Krish

Posted on

2 2 2 2 2

VIM is gem!!

What is VIM? Basically, VIM will help you to code faster than you think, by using some commands. If you learn VIM, it's an advantage while competing with others, as well as it will increase your productivity. Yeah, you will not need a mouse anymore. If you don't get it, don't worry. We will figure it out in this blog!

Official site of VIM
VIM git repo
Here you can download
Or refer some YouTube videos

Download VIM on Linux

sudo apt update
sudo apt install vim
Enter fullscreen mode Exit fullscreen mode

Open your terminal to check vim installed or not.

vim
Enter fullscreen mode Exit fullscreen mode

You can see something like this in your terminal. To exit, type :q
and enter.

Terminal Output

Use VIM in VScode

Add an extension named Vim to your VS code.

VIM extension

Here we start

After that, create a file. You can notice that the cursor has become wider. Also, you can notice the VIM modes in the bottom left of your VS code (Here is NORMAL).

Wider cursur

VIM Mode in VS code

While pressing i you can see the mode become Insert and the cursor become smaller. Now you are in insert mode. Type anything (actually your codes) and press esc so you can escape from the insert mode to normal mode.

Using VIM

Insert mode

Commands starting with : symbols you can see in the bottom left of your VS Code. Type :q to save your code written.

Command with symbols
Below are some codes; play with them and learn more...

Here are the important commands to master VIM.

Basic Navigation

h → Move left
l → Move right
j → Move down
k → Move up
w → Move to the next word
b → Move to the previous word
0 → Move to the beginning of the line
^ → Move to the first non-whitespace character
$ → Move to the end of the line
gg → Go to the beginning of the file
G → Go to the end of the file
:n → Jump to line n (:10 goes to line 10)
Enter fullscreen mode Exit fullscreen mode

Insert Mode

i → Insert before the cursor
I → Insert at the beginning of the line
a → Append after the cursor
A → Append at the end of the line
o → Open a new line below
O → Open a new line above
Enter fullscreen mode Exit fullscreen mode

Editing

x → Delete the character under the cursor
dw → Delete a word
dd → Delete a line
D → Delete from cursor to the end of the line
yy → Copy (yank) a line
yw → Yank a word
p → Paste after the cursor
P → Paste before the cursor
u → Undo
Ctrl + r → Redo
Enter fullscreen mode Exit fullscreen mode

Searching & Replacing

/word → Search for "word"
n → Jump to the next occurrence
N → Jump to the previous occurrence
:%s/old/new/g → Replace all occurrences of "old" with "new"
:%s/old/new/gc → Replace with confirmation
Saving & Exiting
:w → Save
:q → Quit
:wq or :x → Save and quit
:q! → Quit without saving
ZZ → Save and exit (shortcut)
Enter fullscreen mode Exit fullscreen mode

Visual Mode

v → Start visual mode (select text character by character)
V → Start line-wise visual mode
Ctrl + v → Start block visual mode
y → Yank (copy) selected text
d → Delete selected text
> → Indent selected text
< → Un-indent selected text
Enter fullscreen mode Exit fullscreen mode

Windows & Tabs

:split or :sp → Split window horizontally
:vsplit or :vsp → Split window vertically
Ctrl + w + w → Switch between windows
:tabnew → Open a new tab
gt → Switch to the next tab
gT → Switch to the previous tab
Enter fullscreen mode Exit fullscreen mode

Thank you! Happy coding...

Top comments (2)

Collapse
 
vbd profile image
Volker B. Duetsch

I have been using Vim for about 28 years. I have seen many programs come and go during this time. Vim has always been there. I have never regretted learning Vim. And I am still learning something new in Vim today. There is only one thing you should avoid: adjust your Vim config daily ;)
Some notes on Vim can be found in my field notes: github.com/vbd/Fieldnotes/blob/mai...

Collapse
 
arunkrish11 profile image
Arun Krish

Share your thoughts on VIM...

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!