Vim: A Superpower!

Sahil NaikSahil Naik
3 min read

Why Vim editor?

In my opinion, Vim is a powerful yet underrated text editor that can be used to write and edit the code quickly. It offers you speed and efficiency, allowing you to navigate and edit text without leaving the keyboard.


Problems that I faced while learning to use Vim :

  1. Struggled with text insertion in the editor.

  2. Had trouble exiting Vim.

  3. Encountered issues saving changes in the editor and quitting simultaneously.

  4. Needed to exit Vim to run basic Linux commands.

  5. Confusion in normal, insert and command mode.


How I solved those problems?

  1. To insert any text inside the Vim editor, you Press i.

  2. To exit Vim, you Press esc + :q. (Note: If you haven't written any text)

  3. To save the inserted text and quit simultaneously, you Press esc + :wq. (i.e write and quit). If you insert a code and then follow the above command Press esc + :q then you get the following error.

  4. To run Linux commands inside Vim, you Press esc + :! (command name)


Key takeaways :

The first thing I would like you to know is about Normal, Insert and Command mode.

  • When you enter Vim, you are by default in the Normal mode.

  • If you want to insert text or code, you Press i. Then you are eligible to insert a text.

  • When you want enter into command mode, press esc. Now you are eligible to run commands such as quit, save, linux commands and so much more with a colon before.


Bonus tricks :

  • To exit Vim forcefully without saving changes, use :q!. To save changes and quit, use :wq or type :w followed by :q.

  • To enter Insert mode and move the cursor to the end of the line, press Shift + A.

  • To undo changes, press Esc and then u.

  • Move the cursor to the beginning of the line press Esc 0 and to the end with (Shift + 4) $.

  • In Normal mode, use x to delete a character and dd to delete an entire line.

  • Navigate in Normal mode with h (left), l (right), j (down), and k (up).

  • Import file contents of another file with :r filename and run Linux commands with :! command (e.g., :! ls).

  • Use %s/text to replace/new text to find and replace text.

  • Go to the start of the file withEsc + gg and the bottom with Shift + g.

  • Toggle line numbers with :set number and :set nonumber.


Resources that helped me to learn:

Vim - [Free] : https://youtube.com/playlist?list=PLT98CRl2KxKHy4A5N70jMRYAROzzC2a6x&feature=shared


0
Subscribe to my newsletter

Read articles from Sahil Naik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sahil Naik
Sahil Naik

๐Ÿ’ป Sahil learns, codes, and automates, documenting his journey every step of the way. ๐Ÿš€