top of page

VI Editor Tutorial:


VI means virtual editor.

VI is installed in every Unix system

VI editor has to mode:

  1. Command mode:

  • By default mode is command mode.

  • This made enables you to perform admistrative task such as save, cut, copy, pasting, find, replace

  • To return into command mode use Esc button.

  • save command:--> :w, :w<another filename>

  • save+quit--> :wq, ZZ

  • quit without save:--> :q!

  • move within file: k-->up, j-->down, h-->left, l--> right,w-->next word,b -->previous word, u-->undo

  • delete command :

  • x-->delete characters under the current location.

  • X-->delete characters before the cursor location.

  • dw-->delete word

  • d^ -->delete from current cursor to begging of line

  • d$, D -->delete from current cursor to end of line

  • dd --> delete line

  • <n>dd--> delete n line from current cursor.

  • change command:

  • cc--> Removing the contents of the line and leaving in insert mode.

  • cw-->change word

  • r-->replace the character.

  • R-->Overwrites multiple characters begging with current cursor. you must use Esc to stop the overriding.

  • s-->Replace the current character with the character you type.

  • S-->Delete the line the current cursor.

  • Copy and paste command:

  • yy --> Copies the current line.

  • yw --> copies the current word.

  • p -->Puts the copied text after the cursor.

  • P -->puts the copied test before the cursor.

  • Set Command:

  • :set ic -->ignore the case while searching

  • :set ai -->set autoindent

  • :set noai -->unset autoindent

  • :set nu -->set line number

  • :set nonu -->unset linenumber

  • Running Command

  • :! -->vi has capability to run commands within the editor.

  • :! ls -->output of ls command

  • Replacing command:

  • :s/search/replace/g -->substitution command (:s/) enable you to quickly replace word or group of words within your file.

  • g stands for globally.

2. Insert mode:

To edit the file we need to be in insert mode. way to enter in insert mode.

  • i-->insert text before the current cursor.

  • I-->Insert test at the begging of the current line

  • a-->Insert text after the current cursor.

  • A-->insert text at the end of the current line.

  • o-->Create a new line for text entry below.

  • O-->Create a new line for text entry above.


Advanced Command:

  1. word and character search: Vi editor has two search string and character.

/ -->search downward in file.

? -->search upward in file.

n & N -->repeat the previous search command.

^ -->Searches at the beginning of the line.

. -->Matches a single character.

* -->Matches zero or more of the previous character.

$ -->End of the line

[ -->start a set of matching or non-matching expression.


Comentarios


bottom of page