8 Shortcuts To Get Started With Vim

8 Shortcuts To Get Started With Vim

Β·

3 min read

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!! πŸ₯³

CatTypingGIF.gif

πŸ“ Prerequisites:

  • Any Vim editor Or VS Code with Vim extension (I will be using this)

πŸ”΄ Before the shortcuts:

Vim has three text modes:

  1. Normal mode - Where you will use the vim shortcuts
  2. Insert mode - Where you can actually edit the text with normal keystrokes
  3. Visual mode - Where you will select the text

πŸ”„οΈHow to switch between modes:

  • Escape to exit current text mode or to enter Normal mode
  • i to enter Insert Mode
  • v to 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.

  • πŸ‘‰ h for moving right
  • πŸ‘ˆ l for moving left
  • πŸ‘‡ j for moving down
  • πŸ‘† k for 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+6 or ^ to get to the start of the line or the first non-blank character
  • shift+4 or $ to get the end of the line
  • shift+a to append to the end of the line and switch to insert mode

πŸ”š 4. Going to the end or beginning of the file:

  • shift + g or G - to go to last line of the file
  • gg - to go to the first line of the file

↩️ 5. Undo or Redo changes in file

  • u to undo changes
  • ctrl + r to redo changes

πŸ” 6. Search text

  • / followed by the text you are searching for
    • n - to go to next occurrence
    • shift+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 c to the end like :%s/text1/text2/gc to confirm every replacement
      • For every replacement you get to these options
        1. y for replacing the current entry
        2. n to not replace the current entry and skips to next entry
        3. a to change all entries
        4. q to quit
        5. l replace only the first entry and quit

πŸ’Ύ 8. Save and quitting vim

  • shift+zz or :wq! - save and exit the file
  • :q! - exit file without saving

Tada!! You are done.

mission complete

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

Did you find this article valuable?

Support Somnath Paul by becoming a sponsor. Any amount is appreciated!

Β