Vim editor is a tool for creating, editing, merging and performing the operations, as you may used to do in the editors like Wordpad, Notepad, etc. The editor is used more by the programmers as they like to be with their keyboard only, not making much use of a mouse or a touchpad. Besides this, VIM editor has a feature of Autocomplete which is most liked by the developers.
Want to explore with the latest vim editor? Oh, well, it’s comparatively trickier than other editors like notepad & word processors. Vim editor has many advanced features which vi editor does not have. Vim editor is based on commands, but it also support GUI. Vim editor has 3 modes in which only the operations such as copying, pasting, deleting, inserting and saving can be performed . These three modes are named as:
- Command mode
- Insert mode
- Last line mode
1. Command mode: In this mode you can play with the text already written in a file. but you can not insert or add anything to that file. By default, vim editor open ups in command mode only.There are numerous commands by which you can perform editing, some of these are as follows:
h – this is used to move one character left
l – this is used to move one character right
k – this is used to move up
j – this is used to move down
yy – this is used to copy a single line
dd- this is used to delete a single line
p – this is used to paste which you have copied
^ -this is used to reach at a beginning of a line
$ – this is used to reach at end of the line
2. Insert mode: You can enter into the insert mode by simply pressing “i”. This mode is used to insert the content into a file, you can navigate between the lines by the use of arrow keys.
3. Last line mode: To switch to the last line you have to press “: (colon)” then you can perform the operation that you want such as to save a file, quit from the vi editor and many more. For an example:
:set number – this is used to do the numbering in the content
:set nu- this is used to remove the numbering from the content
Steps to Use VIM Editor in Ubuntu
Step 1: To open a file in vim, firstly, go to the path where it is stored. My file is stored under home->Desktop and as I am already in home path, so I will go to the Desktop section. For this the directory has to be changed, so type the command “cd ~/Desktop”.
Step 2: Now the path is changed, open the file you want using the command “vim filename.txt”
I have entered “vim demo.txt” to open the file named as demo.txt.
Step 3: Here you can see the content of the file. We are in Command mode so the operations which are stated earlier can be performed here.
As you can see the cursor is at the letter “s” of the word “lets’, in order to go at the starting point of the line, you have to press “^”.
Step 4: You can see in the figure below, that the cursor has come to the starting point of the line, this means that the above operation worked correctly.
Step 5: Lets go to the start mode by using the “i” command. At the bottom of the terminal you will see “–INSERT–” that confirms, you have successfully entered into the insert mode.
Step 6: Now you can append as much lines as you want in the respective file. I have typed in two lines as shown in the figure below.
To save the changes you need to exit from the insert mode by clicking the “ESC” key.
Step 7: Once you are finished with the editing, you have to enter into the Last line mode by pressing “:” i.e. colon.
To save the file type “w” after colon i.e “:w”.
Step 8: To exit from the vim editor you have to press “:q” which means to quit.
Step 9: If, due to any reason, you are not able to exit or want to close the editor without saving the last editing you’ve performed, then you can forcefully close the editor by using “:q!” command as shown in the figure below.
Step 10: Some other last line mode commands such as “:set number” or “:set nu”, are used to enter numbers into the content that increases the readability of the content, as shown in the image below.
Step 11: The content of the file demo.txt is arranged according to the number of lines present, as demonstrated in the figure.
Step 12: If at, any point of time, you feel to undo the changes, then you can remove the numbers by just typing the “:set nu!” command.
Leave a Reply