Input Mode


The Insert, Append, Open, Change, and Replace commands put vim in Input mode. While vim is in this mode, you can put new text into the Work buffer. You need to press the ESCAPE key to return vim to Command mode when you finish entering text. Refer to "Show mode" on page 184 if you want vim to remind you when it is in Input mode (it does by default).

Inserting Text

Insert (i/I)

The i (Insert) command puts vim in Input mode and places the text you enter before the character the cursor is on (the current character). The I command places text at the beginning of the current line (Figure 6-13). Although the i and I commands sometimes overwrite text on the screen, the characters in the Work buffer are not changed; only the display is affected. The overwritten text is redisplayed when you press ESCAPE and vim returns to Command mode. Use i or I to insert a few characters or words into existing text or to insert text in a new file.

Figure 6-13. The I, i, a, and A commands


Appending Text

Append (a/A)

The a (Append) command is similar to the i command, except that it places the text you enter after the current character (Figure 6-13). The A command places the text after the last character on the current line.

Opening a Line for Text

Open (o/O)

The o (Open) and O commands open a blank line within existing text, place the cursor at the beginning of the new (blank) line, and put vim in Input mode. The O command opens a line above the current line; o opens one below the current line. Use the Open commands when you are entering several new lines within existing text.

Replacing Text

Replace (r/R)

The r and R (Replace) commands cause the new text you enter to overwrite (replace) existing text. The single character you enter following an r command overwrites the current character. After you enter that character, vim automatically returns to Command modeyou do not need to press the ESCAPE key.

The R command causes all subsequent characters to overwrite existing text until you press ESCAPE to return vim to Command mode.

Tip: Replacing TABs

The Replace commands may appear to behave strangely when you replace TAB characters. TAB characters can appear as several SPACEsuntil you try to replace them. They are actually only one character and are replaced by a single character. Refer to "Invisible characters" on page 182 for information on how to display TABs as visible characters.


Quoting Special Characters in Input Mode

CONTROL-V

While you are in Input mode, you can use the Quote command, CONTROL-V, to enter any character into the text, including characters that normally have special meaning to vim. Among these characters are CONTROL-L (or CONTROL-R), which redraws the screen; CONTROL-W, which backs the cursor up a word to the left; and ESCAPE, which ends Input mode.

To insert one of these characters into the text, type CONTROL-V followed by the character. CONTROL-V quotes the single character that follows it. For example, to insert the sequence ESCAPE[2J into a file you are creating in vim, you type the character sequence CONTROL-V ESCAPE[2J. This character sequence clears the screen of a DEC VT-100 and other similar terminals. Although you would not ordinarily want to type this sequence into a document, you might want to use it or another ESCAPE sequence in a shell script you are creating in vim. Refer to Chapter 13 for information about writing shell scripts.




A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net