Vi Editor

The VI editor

The standard Unix/Linux editor

-Now we have vim-improved with move feature.

-When Vi is used system invokes ‘Vim’ because vi is defined alias to vim.

Starting:

# Vi filename

(Open an existing file or editing or a new file is created if the current buffer is saved)

Three operating modes of vi:

1.Command Mode: All the vi command and cursor movement key-strokes can be used. Command such as copying, pasting (put), undo, redo is run is command mode

2.Insert Mode: Actually whatever we want to write from the keyboard to the file is done in this mode. Simply insert mode takes input to the file.

3. Execution Mode: Searching for text, saving, quitting etc is done from here normally followed by (/ or :)

Note:   1. Use: set nu (or number) to display the line number)

2 Use: set nonu (to hide line number)

3. To use color full text in vi this package should be installed

# rpm -q vim-enhanced

INSERT:

a- Insert after the cursor

i- Insert before the cursor

o- Insert to a line below

A= Append to the end of line

I= Insert at the beginning of the file

O= Insert to a line above

Copy, Paste, Delete, Undo, Redo

——————————–

yy – to copy the current line

3yy- copies 3 lines below the cursor position

p – Put below (paste) below the line.

P – Paste above the line

dd – Deletes the current line

5dd -Deletes 5 lines below the cursor

u – Undo the recent change

U – Undo the changes to present line

Ctrl+r -redo

Execution Mode:

:w – write but stay in the buffer.

:q – quit q! (Forcefully quit the buffer)

:wq – write and quit

:x     ,,    ,,   ,,

zz – from command mode.

:wq /var/test (saves in different location)

:r /etc/hosts (opens different file in the same buffer)

:r !cal , :!date – to execute commands

/ and enter searching word to find

eg. /Linux  (text -forward

? And enter searching word to find (backward)

:set ignorecase or set ic (it igone the text case)

:set noic (to disable case)

n= next search in same

N= Next search in reverse direction