Working with Vi editor in Unix
Vi is a very powerful text editor on Unix.
The below resources will help you when dealing with the vi editor in Unix.
This article is intended to work as a basic starting point or something that you can use on a regular basis for the basic needs. In short, this is a vi survival toolkit.
Basic operation modes
Create or Opening a file
vi filename
It will create a file if does not exist, otherwise the file will be opened.
Adding or editing text content
As soon as you open a file in vi, you will be in command mode. To edit the content, press the "Insert" key. This will take you to the Insert mode. Add the content using the keyboard.
Exiting the vi editor
This is by far the task that makes many sweat.
1. When the file content is not changed
Make sure you are in command mode pressing Esc key
:q and press enter key (make a note of the colon)
2. when the file content is changed and you do not want it to be saved[Perhaps the one thing you always should know]
Make sure you are in command mode by pressing Esc key.
:q! and then press enter key
3. when you have changed the file content and it has to be saved
Make sure you are in command mode by pressing Esc key.
:wq and then press enter key
Additional options when dealing with the text content
For the activities like deleting a fill line, some characters, forward and backward string search, please use the below reference.
https://www.cs.colostate.edu/helpdocs/vi.html
Footnote : These are learnings from encounters in the day to day work and there is quite a lot to learn with respect to this tool.
Comments
Post a Comment