14
Chapter 7 Chapter 7 Vi Editor Vi Editor Ref. Pge. 252

Linux fundamental - Chap 07 vi

Embed Size (px)

Citation preview

Page 1: Linux fundamental - Chap 07 vi

Chapter 7Chapter 7Vi EditorVi Editor

Ref. Pge. 252

Page 2: Linux fundamental - Chap 07 vi

Text EditorText Editor

● Common text editors in Linux:Common text editors in Linux:– vivi / / vimvim : most available : most available– emacsemacs : comprehensive : comprehensive– nanonano : simple : simple– geditgedit : GUI : GUI

Page 3: Linux fundamental - Chap 07 vi

Why VI?Why VI?

● The reasons:The reasons:– standardstandard– AvailabilityAvailability

● The The vimvim : :– enhanced versionenhanced version– Linux defaultLinux default

Page 4: Linux fundamental - Chap 07 vi

A Simple way for using A Simple way for using vimvim

vim text.filevim text.file1st: Press 1st: Press ii key key2nd: Insert words2nd: Insert words3rd: Press 3rd: Press EscEsc then then● :wq :wq for saving for saving ● :q! :q! for without saving for without saving

Page 5: Linux fundamental - Chap 07 vi

Vi ModesVi Modes

● Command Mode:Command Mode:– issue commandsissue commands

● Insert Mode:Insert Mode:– insert textinsert text

● Ex (:) Mode:Ex (:) Mode:– extended commandsextended commands

Page 6: Linux fundamental - Chap 07 vi

Switching ModesSwitching Modes

Command Mode

Insert Mode

Ex Mode

vim

i

Esc: Enter

exit

Page 7: Linux fundamental - Chap 07 vi

Cursor MovingCursor Moving

● By character:By character:– h, j, k, lh, j, k, l

● By word:By word:– w, e, bw, e, b

● By line:By line:– 0, ^0, ^– $$– G, G, nnG, ggG, gg

Page 8: Linux fundamental - Chap 07 vi

Editing CommandsEditing Commands

● Delete:Delete:– d, dd, d, dd, nndd, Ddd, D

● Copy:Copy:– y, yy, y, yy, nnyy, Yyy, Y

● Change:Change:– c, cc, c, cc, nncc, Ccc, C

Page 9: Linux fundamental - Chap 07 vi

Other CommandsOther Commands

● Paste:Paste:– p, Pp, P

● Undo:Undo:– uu

● Redo:Redo:– ^r^r

Page 10: Linux fundamental - Chap 07 vi

Other CommandsOther Commands

● Remove:Remove:– X, xX, x

● Replace:Replace:– R, rR, r

● Repeat:Repeat:– ..

Page 11: Linux fundamental - Chap 07 vi

Searching CommandsSearching Commands

● Forward:Forward:– /key/key

● Backward:Backward:– ?key?key

● Search next:Search next:– n, Nn, N

Page 12: Linux fundamental - Chap 07 vi

Inserting CommandsInserting Commands

● On the left:On the left:– i, Ii, I

● On the right:On the right:– a, Aa, A

● Above:Above:– OO

● Bellow:Bellow:– oo

Page 13: Linux fundamental - Chap 07 vi

Extended Commands (:)Extended Commands (:)

!cmd !cmd : run a command: run a commandr !cmdr !cmd : read from command : read from commandr filer file : read from file : read from filew filew file : write to file : write to fileq!q! : quit without saving : quit without savingwqwq : write then quit : write then quitxx : (same as above) : (same as above)

Page 14: Linux fundamental - Chap 07 vi

Options settingOptions setting

set all set all : display current settings: display current settingsset ts=set ts=nn : set tab stop to : set tab stop to n n char. char.set nu/nonuset nu/nonu : line number : line numberset hls/nohls set hls/nohls : highlight searching: highlight searchingset ai/noaiset ai/noai : auto indent : auto indentsyntax on/offsyntax on/off : syntax color : syntax color