It has been a long time since I blogged about the how to get started with VIM. So without delay I should start with basic navigation and editing in VIM.
Before that I just want to say that VIM is very case sensitive (in command mode). “A” is not same as “a”. So if I type “A” it means “A” and not “a”.
There are a few different modes in VIM
- Command Mode
- Insert Mode
- Search mode
When you start VIM, it will be in command mode. In command mode you can move cursor, delete text, search and replace text, navigate in the file. For inserting text you will
have to use “insert” mode. You will not be able to insert text in command mode. Here are the keys for basic navigation:
Move Right ==> l (Small L)
Move Left ==> h (Small H)
Move Up ==> k (Small K)
Move Down ==> j (Small J)
These shortcuts are for people who want to be as fast as fast possible while typing because you do not have to break the flow of your typing with the above navigations.
For people who do not like this the normal Up, Down, Right and Left arrows on their keyboards will work as well :).
For inserting the text you will have to press “i” (Small I) while in command mode. After hitting “i” you will no longer be in command mode and pressing “l”, “h”, “k” and
“j” will actually print these letters. In insert mode you can type in the text as you do normally. To get out of “Insert” mode, press “Esc” key.
Search mode is invoked by pressing “/” in command mode. After that type for whatever you want to and hit the Return key. Press “n” (Small N) to go to next searched item
and “N” (Caps N) to go to previous search item.
What makes VIM an editor of choice is its command mode and the way you can navigate within it without touching mouse. Here are some commands(which I know and use):
gg ==> Go to first line in the document
G ==> Go the last line
nG ==> Go to line number “n”. 25G takes you to the 25th
line in the document.
c$ ==> Chage to the end of line
cw ==> Change word
dd ==> delete current line
dd ==> delete next n
lines where n
is any number
yy ==> copy current line to buffer
yy ==> copy n
lines to buffer
P (small) ==> paste above the line where cursor is
p (caps) ==> paste below the current line where cursor is
o (small) ==> Add a new line below cursor position and invoke insert mode
O (caps) ==> Add a new line above cursor position and invoke insert mode
The “dd” puts the deleted lines in buffer so it can be also used as cut-paste in conjuction with “p” or “P” command.
[…] Be a Rebel What is Fate, But what we make… Skip to content HomeAbout MeThe Beginning… ← Night on the Baner Road VIM Part II: Basic Navigation and Editing → […]