Learning the vi Editor

Learning the vi EditorSearch this book
Previous: 2.5 Joining Two Lines with J Chapter 2
Simple Editing
Next: 3. Moving Around in a Hurry
 

2.6 Review of Basic vi Commands

Table 2.1 presents a few of the commands you can perform by combining the commands c, d, and y with various text objects. The last two rows show additional commands for editing. Table 2.2 and Table 2.3 list some other basic commands. Table 2.4 summarizes the rest of the commands described in this chapter.


Table 2.1: Edit Commands
Text ObjectChangeDeleteCopy
1 wordcwdwyw

2 words, not counting punctuation

2cW or c2W2dW or d2W2yW or y2W
3 words back3cb or c3b3db or d3b3yb or y3b
1 lineccddyy or Y
To end of linec$ or Cd$ or Dy$
To beginning of linec0d0y0
Single characterrx or Xyl or yh
Five characters5s5x5yl

Table 2.2: Movement
MovementCommands
<-,-v,-^, ->

h, j, k, l

To first character of next line+
To first character of previous line-
To end of worde or E
Forward by wordw or W
Backward by wordb or B
To end of line$
To beginning of line0

Table 2.3: Other Operations
OperationsCommands
Place text from bufferP or p
Start vi, open file if specifiedvi file
Save edits, quit fileZZ
No saving of edits, quit file:q!

Table 2.4: Text Creation and Manipulation Commands
Editing ActionCommand
Insert text at current positioni
Insert text at beginning of lineI
Append text at current positiona
Append text at beginning of lineA
Open new line below cursor for new texto
Open new line above cursor for new textO
Delete line and substitute textS
Overstrike existing characters with new textR
Join current and next lineJ
Toggle case~
Repeat last action.
Undo last changeu
Restore line to original stateU

You can get by in vi using only the commands listed in these tables. However, in order to harness the real power of vi (and increase your own productivity), you will need more tools. The following chapters describe those tools.


Previous: 2.5 Joining Two Lines with J Learning the vi EditorNext: 3. Moving Around in a Hurry
2.5 Joining Two Lines with J Book Index3. Moving Around in a Hurry

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System