Oracle DBA, How To, Error, Cause and Action

vi Editor

Just remember that there are two modes in vi editor

1. Command Mode
2. Insert Mode


Command Mode

Once the file is opened, you are in command mode. From command mode, you can:

- Invoke insert mode
- Issue editing commands
- Move the cursor to a differ ent position in the file
- Invoke ex commands
- Invoke a Unix shell
- Save or exit the current version of the file


Insert Mode

In insert mode, you can enter new text in the file. Press the Escape key to exit insert mode and return to command mode. The following commands invoke insert mode:

a Append after cursor.
A Append at end of line.
c Begin change operation.
C Change to end of line.
i Insert before cursor.
I Insert at beginning of line.
o Open a line below current line.
O Open a line above current line.
R Begin overwriting text.
s Substitute a character.
S Substitute entire line.


Example

I want to create file in /tmp with filename my_first.txt
The content of the file is simple words hallo world

1. type vi /tmp/my_first.txt




2. When you hit enter you will be in Command Mode of vi editor


3. From Command Mode you can type "i" to go to Insert Mode as you can see from the bottom is written "INSERT"
you can start type into the vi editor.



4. After you complete the editing press "ESC" to go back to Command Mode, as you can see the word Insert at the bottom is disappear



5. if you want to go back to edit then press "i" and to save and quit from vi editor file type ":wq" and hit Enter.



6. now the file is create and the content is saved.

No comments:

Post a Comment

Thanks for your comment.