Vim Essentials - Introduction- 3 mins
Vim is one of the most powerful text editors. Although it has a steep learning curve, but it’s worth the time.
I’m starting this series, in hope to provide some useful information, so that, new learners can get help.
By default each unix has Vi installed. But to take full advantage of Vim editor, you have to install full package first.
I’m using Ubuntu, to install vim I need to run just the following commands
Now we can open the file by going to the directory and using the command
or we can use full path to the file like
Any of this command will open the file inside the vim editor. Now you might wonder… Hey! this doesn’t look like an existing editor. Where’s the line number or syntax highlighting. Let’s configure it-
In your root directory create a file named
.vimrc. You can do it mannually or create it using the command
open in the editor and press
i to insert text.
i command tells the vim editor that we want to write/insert something into the file.
Insert following lines. Type
:wq and press Enter.
: opens for any command we want to give.
w stands for Write and
q stands for Quit. If you want to stay in editor with just inserting the lines then type only
Navigation in vim editor requires four buttons
In previous section we saw that
i is for insert and
w is for writing in the file. We can delete using
d. Fun part is the command
d has few associates. If we type
d3k it will delete 3 letters on the right. the breakdown is
so if we type
d3l it will delete 3 lines above the selected line.
For undo use
P.S. All of these commands works in Visual mode only. Insert itself is a mode, and we can’t do these operations when insert mode is active.
You can type
:q to quit the editor. However if the file opened in the editor has unsaved changes then this will throw an error. You either have to save the change and quite editor (
:wq) or you have exit the editor without changing the editor (
Vim is extremely fun if you are used to it. There are lots of capabilities including plugin management available for Vim. I hope to write about them in the future. Visit Vim official site for details.