INTRODUCTION
Vi is the default and most commonly used text editor in Linux/Unix operating systems. Vim is an enhanced version of vi which is original Linux/Unix text editor.
Most of the Linux administrator prefer vim, for its bundled of features and ease of use. It can be used to edit all kind of text files e.g. plane text files, Linux configuration files.
`
Vi is the default text editor in Linux, to get the more advanced editor vim you need to install it using the following command:
SOLUTION
Vim Installation:
yum install vim -y
Vim Mode:
Before using you should know that it can operate in two modes one is command mode and other is insert mode.
Once you will start vim editor it will always start in command mode. In this mode you can search, replace, copy, paste and other editing task.
The other mode is the editor mode where you can actually modify text into the editor.
Start with Vim
We start vim with the command vim then specify the desire text file name. Suppose we have one file already exist on /tmp directory named info.txt.
To open a file in vim text editor, run the vim command with filename as an argument.
See Example:
vim /tmp/info.txt
If the file doesn’t exist on the specified path, the edit will create and open new file with same file name which is mentioned in above command, else it will open the existing file.
Change Mode:
The editor will open the file in command mode, where you can perform some editing task and move the cursor by using arrow keys on your keyboard.
But you cannot edit the text until you press I button. Pressing I will activate the insert mode.
Image: Command Mode:
Image: Insert Mode:
Insert Text:
Once you are in insert mode you can move your cursor freely anywhere in the file using arrow keys and add or delete contents of text file.
Image: Insert Mode:
Once you are done your editing you have to come back in command mode to be able save changes, you have to press Esc key to change mode from insert to command mode.
To save file, type :w command and press enter key.
To quite from the editor, type :q command and hit enter.
Tip: – Quick way to write your changes and quite, type :wq command and hit enter.
Copy & Paste:
To copy and paste line, open file in vim editor move cursor on desire line and press yy then to paste after your cursor position press p.