Vim: A Superpower!
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 :
Struggled with text insertion in the editor.
Had trouble exiting Vim.
Encountered issues saving changes in the editor and quitting simultaneously.
Needed to exit Vim to run basic Linux commands.
Confusion in normal, insert and command mode.
How I solved those problems?
To insert any text inside the Vim editor, you Press i.
To exit Vim, you Press esc + :q. (Note: If you haven't written any text)
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.
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 thenu
.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 anddd
to delete an entire line.Navigate in Normal mode with
h
(left),l
(right),j
(down), andk
(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 with
Esc + gg
and the bottom withShift + 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
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. ๐