VI Editor Part Two


Let continue VI Editior other commands which are more useful and very important



Basic Editing

To use editing commands we must be in command mode.  Following
commands will be interpreted differently depending upon whether they are used in lower or upper case.  some of editing commands can be preceded by a number to indicate a repetition of the command.

Deleting (or Cutting) Characters, Words and Lines

To delete a character, we need to place cursor on first place of our character, then we can use following commands.

x deletes the character under the cursor.
X deletes the character to the left of the                 cursor.
dw deletes from the character selected to the                 end of the word.
dd deletes all the current line
D deletes from the current character to the                 end of the line.

Note: Preceding the command with a number will delete mulitple chatacters.  for example 9x will delete the character selected and then next 8 characters where as 9X will delete 9 characters to the left of the currently selected character.  The command 7dw will delete 7 words where as 7dd delete seven lines.

Pasting Text using Put

When we delete or cut text and want to reinsert it in another location of the document.  The Put command will paste in the last portion of text that was deleted since deleted text is stored in a buffer.  To use this command, place the cursor where we wish to appear deleted text.  Then use p to reinsert the text.  If we are inserting a line or paragraph use the lower case p to insert on the line below the cursor or upper case P to place in on the line above the cursor.

Copying Text with Yank

If we want to make a duplicate copy of existing text then use yank and put commands to accomplish this function.  Yank copies the selected text into a buffer and holds it until another yank or deletion occurs.  Yank is usually used in combination with a word or line object as one.

yw copies a words into a buffer (6yw copies 6                 words)
yy copies a line into a buffer (5yy will copy                 5 lines)

Replacing or Changing characters, Words and Lines

Lets see following commands.

r replaces the current character with the                  next character which we enter.  Once we                  enter the character we will return to                 command mode.
R put us in overtype mode until we hit ESC                 which will return to command mode.
cw changes and replaces the current word with                  text that we type.  A dollar sign marks
the end of the text we are changing.  Press                 Esc once we finish and it will return to                 command mode.

Inserting Text

If we want to insert text in a line then press i it will get into insert mode and then we can insert the text and press ESC to return command mode.

Inserting a Blank Line

To insert a blank line below the line where our cursor is currently located on, use the o key and then hit ESC to return to command mode.  Use O to insert a line above the line the cursor is located on.

Appending Text

To append or add any text at any place in our file use append command a which is almost like insert command i except that it insert text after the cursor rather than before it.  Append is probably used most often for adding text to the end of a line.  Place cursor where we want to append a text and press a once we done with appending press Esc to go back to command mode.

Joining Lines

To join the line use command J.  Place cursor on the first line to join and press type J.  We can use precede J with number to join multiple lines like 3J join 3 lines.

Undoing

These command is used to undo the words if there is any mistake happen in file.

u undoes the last change you made anywhere in                 the file.  Using u again will undo the                 undo.
U undoes all recent changes to the current                 line.. We can not have to move from the                 line to recover the original line.


 Click here Third part of VI editor.

Post a Comment

1 Comments

  1. Adding to Kalyan post...

    d$ - Deletes till the end of the line
    d10 - Deletes 10 lines from the current cursor position

    dG - delete from current position to till end of the file

    ReplyDelete
Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)