What is VI editor
VI Editor is most popular editor in linux operating system.It has two mode Command and insert.In command mode you specify operation and insert mode specify the text to be enter. It is faster editor than other because there are shortcut keys defined which makes faster editing in the file.
1.Inserting text
To insert text in file various command is used such as i , I etc. ESC key is pressed to come out from insert mode
Keys | Description |
---|---|
i | insert text to left of cursor |
I | insert text at beginning of line |
a | insert text after character on with |
A | Begins inserting at end of current line |
o | insert text at new line before the current line |
O | insert text at new line after the current line |
2. Appending text
this command is used to append the text anywhere
Keys | Description |
---|---|
shift+A | Append at end of line |
shift+I | Append at beginning of line |
shift+O | Append at above the current line |
shift+R | Start overwrite at current position |
3. Moving cursor
By default the cursor will be at upper left corner of editor.the keys which are included in the moving cursor provide the feature of moving the cursor from one place to another
Keys | Description |
---|---|
n | Set cursor location to left of one character |
l | Set cursor location to right of one character |
k | move cursor one line up |
j | move cursor one line down |
b | move cursor one word backward |
w | move cursor one word forward |
preserving text
press ESC button and type : before typing the below command
Keys | Description |
---|---|
x | replace old copy of file with new copy and quite |
iq | quit with saving change |
iw | saving without leaving screen |
iwq | save and quit file |
iwd | to exit |
5. Display text
VI editor allows to view the file like cat command with feature of the editing
Syntax
VI filename
6.Deleting text
These command is used to delete the text from the file
Keys | Description |
---|---|
dd | delete the current line |
dw | delete the word above ht cursor |
D | delete text from current cursor location to end of line |