8 Shortcuts To Get Started With Vim

Vim has too many shortcuts and it can be confusing π΅βπ« for newcomers. So, I comprised a list of 8 shortcuts from the perspective of a person coming from normal text editors β¨οΈ.
For the people who are asking why not just go through Vim Tutor? Vim tutor is easy but It has too many shortcuts to wrap our mind around. Normally We don't use all of them all the time so learning all at the same time is not productive as we will eventually forgetπ΅ them!
To develop the πͺπ§ muscle memory, first we have to work with these limited shortcuts.
So, let's get started!! π₯³

π Prerequisites:
- Any Vim editor Or VS Code with Vim extension (I will be using this)
π΄ Before the shortcuts:
Vim has three text modes:
- Normal mode - Where you will use the vim shortcuts
- Insert mode - Where you can actually edit the text with normal keystrokes
- Visual mode - Where you will select the text
ποΈHow to switch between modes:
Escapeto exit current text mode or to enter Normal modeito enter Insert Modevto enter Visual Mode
Look at the status bar at the bottom to know which mode you currently in.
β¨οΈ Shortcuts:
π§ 1. Navigate cursor in Normal mode:
In Vim, we use h, j, k, l to navigate between lines.
- π
hfor moving right - π
lfor moving left - π
jfor moving down - π
kfor moving up
π 2. Edit Text
First enter Insert mode using i. That's it! Now Text is editable normally.
Use Escape to exit Insert mode.
π 3. Navigate to start or end of the line in normal mode
shift+6or^to get to the start of the line or the first non-blank charactershift+4or$to get the end of the lineshift+ato append to the end of the line and switch to insert mode
π 4. Going to the end or beginning of the file:
shift + gorG- to go to last line of the filegg- to go to the first line of the file
β©οΈ 5. Undo or Redo changes in file
uto undo changesctrl + rto redo changes
π 6. Search text
/followed by the text you are searching forn- to go to next occurrenceshift+n- to go to previous occurrence
π 7. Replace text
:%s/text1/text2/g- replace text1 with word you want to change and text2 is the replacement word- add
cto the end like:%s/text1/text2/gcto confirm every replacement- For every replacement you get to these options
yfor replacing the current entrynto not replace the current entry and skips to next entryato change all entriesqto quitlreplace only the first entry and quit
- For every replacement you get to these options
- add
πΎ 8. Save and quitting vim
shift+zzor:wq!- save and exit the file:q!- exit file without saving
Tada!! You are done.

Liked my article? Give a thumps up!! Have some feedbacks? Comment them below!!


