logo
logo

Get in touch

Awesome Image Awesome Image

Development May 19, 2014

How To Use vim Editor in linux

Writen by Taeyaar Support

comments 0

Vi editor is pre-installed in almost every Linux operating system. It’s very useful if you know how to use it actually. People usually prefer using NANO over Vi but vi editor got way more features than nano editor. First you should know how to open a file in vi editor. All you have to do is typing

Vi ‘filename’

To open the existing file name ‘filename’

To create a new file using vi editor, type vi newfilename

Now lets proceed to main thing now

There are a basically two modes in vi editor, first one is command mode and second one is text mode. It’s very simple. In command mode you can move your cursor and delete the characters, lines, two lines etc. where in text mode you just simply type like you do in a simple text editor. By default  vi editor is in the command mode. Now I’m going to tell how to switch between these two modes. It’s very simple. As I said you are in command mode by default when you start your vi editor. You have to press ‘I’ key to get into insert mode or text mode where you can enter lines, paragraphs etc. After completing your document simple go back to command mode if you want to make some changes using your cursor. To get back into command mode you have to press ESC key.

You can’t move cursor freely in command mode. There are specific buttons to move the cursor that is: H,J,K,L. ‘H’ and ‘L’ is used to move cursor left and right respectively and ‘J’ and ‘K’ is used to move the cursor down and upwards respectively. Now you know how to open a file using vi editor, getting into either command mode or insert mode, basically knows how vi editor actually works now. Wasn’t it so easy?

Okay now we may proceed to next part of this tutorial where you’ll know how to delete specific word exact after the cursor and some other similar things.

I’m going to create a simple table in which you’ll know how to specific task with specific keyword. Here it is:

X- delete a character before the cursor

x – delete a character

4x – removes 4 charactesr

dw – delete a full word

3dw – delete three words

Dd – delete whole line

2dd – delete two lines

D – to delete from the cursor to the end of file

u- undo most recent edit

U – undo all edits on single fille

 

One more way to search a specific keyword in your file is typing ‘./’ without quotes and your keyword name and press enter.

For example: /.keyword

These aren’t all the shortcuts but I think these are enough to use vi editor. I mean its like knowing something than nothing.  Alright after you’ve made changes to your file now it’s time to exit the file. It’s very important to save your file that can be done in command mode. Get into command mode and

Type ZZ and press enter. This will saves your fill and quits vi editor. You can also type w and press enter but it will only save your file. So, to save your file in vi editor get into command mode type 2 and press enter. In some case you do not want to save the changes you can quit vi editor by typing q! and pressing enter. I hope I helped you, please leave your feedback in the form of comment. I also allow anonymous commenting so you do not need to register. Good luck!

Tags : ,