Introduction to viIntroduction to viIntroduction to viIntroduction to vi
Intro to vi vi is a ubiquitous text editor. It is available for Linux, Unix, Mac OS X and
Windows (from http://www.winvi.de/en/ and others). To run vi, simple type
vi vi test.cpp
Intro to vivi has 3 modes:
1. edit mode
2. insert mode
3. command mode
vi mode: editEsc return to edit mode/search-string/ search againarrow keysRet next line^ beginning of line$ end of linex delete chardwdelete worddd delete linen dd delete n linesu undoCtrl-b backwards a screenful of textCtrl-f forwards a screenful of textCtrl-r redo
vi mode: inserta start adding after cursorA start adding at end of linei insert in front of current cursor positionI start adding in front of lineo open a new line underneath current lineO open a new line above current line
Esc exit insert mode
vi mode: commandCommand mode is entered with : from edit/insert mode.
:q quit (if changes haven’t been made):q! quit without saving changes:w save changes; don’t quit:x save changes and quit
copy-paste steps:1. Place cursor (anywhere) on line you wish to
copy.
2. shift-y yank (makes a copy of the line) or n shift-y to yank n lines
3. Move to location where you wish to paste line.
4. shift-p put
cut-paste steps:1. Place cursor (anywhere) on line you wish to
cut.
2. dd delete line or n dd to delete n lines
3. Move to location where you wish to paste line.
4. shift-p put
Remember…Esc return to move/modify mode
:x save changes; quit
:q quit
:q! quit without saving changes
dd delete line
dw delete word
i insert
u undo