This document also uses several fonts to help clarify the meaning of the text.
|fixed||Literal commands you type appear in Courier font|
|italic||Variables used with commands will appear in italics|
|bold||Keys or elements that you must click appear in bold|
|[ ]||Optional variables will appear in square brackets|
Copying ("Yanking") and Pasting Text
Vi allows you to copy or delete blocks of text and place them elsewhere in your document. The put commands below will insert into the document any text which has been put into the buffer by the delete commands above or the yank (copy) commands below:
|[num] yw||copy num words into the buffer, starting with the current word from the cursor on|
|[num] yy||copy num lines into the buffer, starting with the current line|
|[num] Y||copy num lines into the buffer, starting with the current line|
|p||put any text in the buffer after or below the cursor|
|P||put any text in the buffer before or above the cursor|
The example below illustrates the copying feature. In this example, the cursor is initially positioned before the word uncomment, next type 4yy to yank 4 lines into the buffer, then move the cursor to a destination position where you will place the text. Type p, to place the contents in the buffer below the cursor.
Note: The four lines have been duplicated immediately below their original position.
The following commands allow you to delete single characters, words, or whole lines of text with a single command. Most can be preceded by a number to delete more than one character, word, or line at a time. For example, 3dd would delete three lines at once. When the number is not specified, one character, word, or line is assumed. These commands put the deleted text into the buffer, which can then be placed elsewhere in the document by using the put commands explained later in this guide. While in input mode, you can use the Backspace key to correct mistakes on the current line of text.
|x||delete character under cursor|
|[num] x||delete num characters from cursor forward|
|X||delete character before the cursor|
|[num] X||delete num characters before the cursor|
|[num] dw||delete num words starting with the current word from the cursor on|
|D||delete text from the cursor to the end of the current line|
|[num] dd||delete num lines starting with the current line|
Vi has several commands that allow you to change an existing piece of text without first deleting it; the change commands overtype the current text.
|[num] cw||change num words, starting at the cursor in the current word - the word(s) will be replaced by any text you type until you press Esc|
|C||change the current line from cursor to end - the current line will be replaced by any text you type until you press Esc|
|r||replace the current character (you do not need to press Esc)|
|R||edit the current line from cursor to end in typeover mode - you will remain in typeover mode until you press Esc (you can press Return to insert more lines before pressing Esc)|
|s||replace the current character - the current character will be replaced by any text you type until you press Esc|
|S||replace the entire current line - the current line will be replaced by any text you type until you press Esc|