Hai, Welcome to kondurian's World !

 

VI Editor

Page history last edited by nag 2 yrs ago

VI Editor

 

VI, the famous text editor is distributed with different Linux flavours.

It has highly flexible, robust and friendly commands that users can use to edit the files very easily.

 

Modes in VI Editor

  • ctrl+x is a mode that is sub-mode of the insert mode.

 

Entering and Exiting VI Editor

 

1. At command prompt type

vim filename

 

2. Press the key (to make sure you are in Normal mode).

 

3. Type

:q!

This exits the editor WITHOUT saving any changes you have made.

If you want to save the changes and exit type

:wq or :x

 

Moving the Cursor

 

To move the cursor from current position to left, down, up and right by one position use the h,j,k and l keys respectively.

 

Hint: The h key is at the left and moves left.

The l key is at the right and moves right.

The j key looks like a down arrow

 

 

How to move from one paragraph to other?

Use } key to move down by a paragraph and { to move up by a paragraph.

 

How to move from top to bottom of a file and vice versa?

Use G or ]] to end of file

gg or [[ to begining of file

 

How to move to a location required?

Marks are very much useful in this case.

The advantage is that marks are no limited to functions, enums etc. as in use of "ctags"

Mark a location using ma and after moving some other location and

to come back to the location marked use 'a. Lower-case letters are used to move within a file.

 

How to move between different files?

Use upper-case letters to move between different files. Such as mA and 'A

 

How to move to the declaration of a variable?

use gd. gd is for Goto Declaration

For moving to global declaraion use gD

 

Text Editing

 

    • Deletion

While in Normal mode press x to delete the character under the cursor.

 

    • Insertion

While in Normal mode press i to insert text.

 

When the changes were made to the file, press Key to come back to the normal mode.

 

Deleting

 

The format for the delete command "d" is as follows:

Number d object or d number object

Where:

number is how many times to execute the command (Optional field, defalut is 1)

d is the command to delete

object is what the command will operate on. Objects are described below:

A short list of objects:

w - from the cursor to the end of the word, including the space.

e - from the cursor to the end of the word, NOT including the space.

$ - from the cursor to the end of the line.

 

Examples:

dw - delete to the end of word from cursor position.

de - delete to the end of word not including space.

d$ - delete to the end of line from cursor position.

 

But an excpetion is using dd.

dd - delete complete line in which line cursor is present.

 

Undo and Redo

Press u to undo the last commands, U to fix a whole line.

 

Example:

* Type x to delete the first unwanted character.

* Now type u to undo the last command executed.

* This time fix all the errors on the line using the x command.

* Now type a capital U to return the line to its original state.

* Now type u a few times to undo the U and preceding commands.

* Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times to redo the commands (undo the undo's).

Comments (0)

You don't have permission to comment on this page.