Web Development

Basic command of VI editor

1. Moving the cursor
2. Deleting Characters
3. Deleting words
4. Deleting lines
5. Replacing Characters
6. Replacing Words
7. Replacing Lines
8. Inserting Text
9. Appending Text
10. Opening a Blank Line
11. Joining Lines
12. Searching
13. Command in quick




Moving the cursor
The cursor is controlled with four keys: h, j, k, l.

Key     Cursor Movement
————————————————
h     left one space
j     down one line
k     up one line
l     right one space




Deleting Characters
You can delete characters by following way

To delete single character, move the cursor on the desired character and then type x
To delete four characters(the one under the cursor and the next three) then type 4x
To delete the character before the cursor then type X (uppercase)




Deleting words
You can delete word by following way

To delete a word, move the cursor to the first letter of the word, and type dw
To delete next four words then type 4dw




Deleting Lines
You can delete lines by following way

To delete a whole line then type dd
To delete next four lines then type 4dd
To delete from the cursor position to the end of the line then type D (uppercase)




Replacing Characters
To replace one character with another:

Move the cursor to the character to be replaced.
Type r
Type the replacement character.




Replacing Words
To replace words:

To replace one word with another, move to the start of the incorrect word and type cw. The last letter of the word to be replaced will turn into a $. You are now in insert mode and may type the replacement. The new text does not need to be the same length as the original. Press <Esc> to get back to command mode. To replace three words, type 3cw.




Replacing Lines
To change text from the cursor position to the end of the line:

Type C (uppercase)
Type the replacement text
Press <Esc>




Inserting text
To insert text in a line:

Position the cursor where the new text should go
Type i
Enter the new text
The text is inserted BEFORE the cursor




Appending Text
To add text to the end of a line:

Position the cursor on the last letter of the line
Type a
Enter the new text
This adds text AFTER the cursor




Opening a Blank Line
To insert a blank line below/above the current line:

To insert a blank line below the current line, type o (lowercase)
To insert a blank line above the current line, type O (uppercase)




Joining Lines
To join two lines together:

Put the cursor on the first line to be joined then type J
To join three lines together:Put the cursor on the first line to be joined then type 3J




Searching
To move quickly by searching for text, while in command mode:

Type / (slash)
Enter the text to search for
Press <Return>
The cursor moves to the first occurrence of that text
To repeat the search in a forward direction, type n
To repeat the search in a backward direction, type N




Different command
There are different command:

To undo your most recent edit: u
To undo all the edits on a single line: U
forward word by word: w
backward word by word: b
to end of line: $
to beginning of line: 0 (zero)
to top line of screen: H
to middle line of screen: M
to last line of screen: L
to last line of file: G
to first line of file: 1G
scroll forward one screen: <Control>f
scroll backward one screen: <Control>b
down one-half screen: <Control>d
scroll up one-half screen: <Control>u
To save the file and quit vi: ZZ
To quit vi, and discard any changes your have made since last saving: q!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s