14
Vi Editor TA for ITIS3100: Xu Fei [email protected] 2008-01

Vi Editor TA for ITIS3100: Xu Fei [email protected] 2008-01

  • View
    216

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Vi Editor

TA for ITIS3100: Xu [email protected]

2008-01

Page 2: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Agenda

• Text Editor in Linux

• How to use vi Start vi First look at vi vi mode Switch to insert mode copy, cut and paste undo search save and exit

• Reference

Page 3: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Text Editor in Linux

• We have several choices: vi vim gedit (for GNOME) like the NotePad in Windows And many, many others

Page 4: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Starting vi / vim

• Use vi to open an already existing file by typing vi file-name

• Create a new file by typing vi new-file-name

Page 5: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

First look at vi

Page 6: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

First look at vim

Page 7: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

vi mode

• vi has two modes: command mode insert mode

• In command mode, the letters of the keyboard perform editing functions (like moving the cursor, deleting text, etc.). To enter command mode, press the escape <Esc> key.

• In insert mode, the letters you type form words and sentences. Unlike many word processors, vi starts up in command mode.

Page 8: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Switch to insert mode

• Type the following key:i -- to insert mode at course position

a -- to insert mode where course back a character

Page 9: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Switch to insert mode (CONT.)

I -- to insert mode where course jump to the line head

A -- to insert mode where course jump to the line end

o -- to insert mode and begin a new line under course position

O -- to insert mode and begin a new line before course position

s -- to insert mode and delete the character at course position

S -- to insert mode and delete the line at course position

Page 10: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Delete and block operation -- cut, copy and paste

• Switch to command mode, pressing the escape <Esc> key. Type v, switch to block operation move course to select block c to cut, y to copy p to paste the block to right position of course

• Switch to command mode, pressing the escape <Esc> key. Use shortcuts for delete dd -- delete the current line dw -- delete the current word

Page 11: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

undo

• Switch to command mode, pressing the escape <Esc> key. :u -- undo last operation :e! -- give up all operations and begin edit again

Page 12: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Search in text

• vi supports to search and find a text in the whole file

• Switch to command mode, pressing the escape <Esc> key. /keyword -- to search forward for the keyword

?keyword -- to search backward for the keyword

• type n on the keyboard to find the next

Page 13: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

Save and exit

• Switch to command mode, pressing the escape <Esc> key. :w -- save file :q -- no change and quit :wq -- save file and quit :q! -- force to quit, no matter change file or not

:x –- save file and exit vi

Page 14: Vi Editor TA for ITIS3100: Xu Fei fxu@uncc.edu 2008-01

More reading

• http://www.washington.edu/computing/unix/vi.html

• http://www.uwyo.edu/ASKIT/displaydoc.asp?askitdocid=258&parentid=1

• http://sparky.rice.edu/~hartigan/vi.html