Previous Table of Contents Next


Scrolling

You can use the following six commands to scroll the buffer forward or backward to view text a screen at a time.

nCtrl-E Scroll the display window forward (down) n lines.
nCtrl-Y Scroll the display window backward (up) n lines.
nCtrl-F Scroll forward (down) n full screens.
nCtrl-B Scroll backward (up) n full screens.
nCtrl-D Scroll forward (down) n half screens.
nCtrl-U Scroll backward (up) n half screens.

Ex Mode

The following commands may be used to interface with the ex line editor and return to the vi screen editor.

Q
q
Enter ex mode, return to vi mode with :vi. The ex mode is the same as entering and using the ex line editor. You may want to enter ex mode if you have a lot of substitutions to perform.
: Enter temporary ex mode. Precede each ex command you need to perform with a : (colon); this causes vi to send the command to ex for processing.
:vi Enter/Return to vi mode. If you are in ex you can enter or return to vi.
:open Enter to open mode.

Miscellaneous

& Repeat last substitute command.
% Find matching ( ), [ ], or { }.
nG Go to line n (default: last line).
Ctrl-G Give status of current file.
Ctrl-] Go to tag described in next word.
Ctrl-^ Edit alternate file if two files are being edited and no updates since last write (see :e #).
Q
 q
Enter ex mode.
: Enter temporary ex mode.

MANIPULATION COMMANDS

Text Manipulation is not a true vi mode. It is a combination of the text manipulating commands of command mode and all the commands of insert mode. To leave insert mode and return to command mode, you MUST press Esc. If at any time you feel lost or wish to abort a command, press Delete or Esc. The insert, append and open commands all enter the insert mode. A dollar sign ($) will appear at the end of units of text that are being changed.


NOTE:  
Deleted/Yanked text is stored in the undo register unless a register is defined, refer to the section on Registers and Buffers.



Inserting Text

These commands allow various ways to insert text into the file. You must press Esc or Delete to exit insert mode. The text (txt) in the following commands may be any amount of text you need to type. It is advisable to press Return after each sentence punctuation and have your wrap margin set to a reasonable number. One sentence should be broken into multiple lines to make later editing easier.

atxt<Esc> Append new text after the cursor on the current line.
Atxt<Esc> Append new text at the end of the current line.
itxt<Esc> Insert new text before the cursor on the current line.
Itxt<Esc> Insert new text before the first text on current line.
otxt<Esc> Open the buffer after current line (a new blank line is created).
Otxt<Esc> Open the buffer before current line (a new blank line is created).

Special Insert Command Characters

You must be in insert mode for these keys to function. These are special characters that may be used when in insert mode only.

Ctrl-@ Repeat last insert if entered as first character of insert.
Ctrl-D Backtab over autoindent (one shift width); autoindent must be set.
^Ctrl-D Remove autoindent for current line; autoindent must be set.
0Ctrl-D Remove autoindent until the next autoindent character (Ctrl-T) is typed.
Ctrl-T Tab over the amount specified by the shiftwidth.
Ctrl-V Escape the special meaning of insert characters and allow insertion of nonprinting characters. The Ctrl-J (new-line) character cannot be inserted as a visual character, nor can the Ctrl-I (tab).
Ctrl-W Erase last word of input.
\ Escape the special meaning of insert characters. The Ctrl-V is a better, more reliable method.
Backspace Erase last character of input by pressing your backspace character. The default is # but you may have set it to Ctrl-H using stty.
Kill Erase current line of input by pressing your line kill key; the default is @ but you may have set it to Ctrl-U using stty.
Delete Exit insert mode abnormally by pressing Delete.
Esc Escape insert mode; return to command mode.

Operators

Follow an operator with any motion command to affect units of text. Enter an operator twice to affect lines. Operators cannot be mixed. The txt esc should be used after the c OPR MOT command. It is not used on the commands listed (to save space). A number x may be placed before or after an operator. If a number, x, precedes the operator and another number, y, follows the operator (xOPRyMOT) then the numbers are multiplied, x * y = z, and the operator function is performed on z repetitions of motion (e.g. 5d4d = 20dd = d20d; any of these commands will delete 20 lines of text).


Operator Description

c Change text.
d Delete text.
> Indent (Shift right) text.
< De-indent (Shift left) text.
y Yank (Cut/Store) to register.
! Filter text through UNIX command and replace.
= Pretty print LISP s-expressions.
xOPRnMOT[txt] Perform function specified by operator OPR, x multiplied by n motions MOT. If the operator is an insert-oriented command then insert the txt text and press Escape when finished.

Changing Text

Combine c with any motion command to change units of text. The following list contains aliases or shorthand commands for performing changes and various other text changing commands.

ns Substitute n characters.
ncc Change n entire lines (see S below).
nC Change the rest of the current line and the next n lines.
nS Substitute n entire lines (see cc above).
~ Invert current character case and move right one space.
xcnMOTtxt Change text defined by x multiplied by n motions with new txt text.

Deleting Text

Combine d with any motion command to delete units of text. The following list contains aliases for the d operator and various other deletion-oriented commands. The deleted text is stored in the undo register and if the text includes new-lines, then it is placed in register 1. As more line-oriented deletes are made, the text is shifted to the next higher register. Deleted text may be retrieved from registers using the p command. The last delete can be retrieved using the u (undo) command.

nx Delete the current character and shift text left.
nX Delete the character to the left of the cursor.
nxp Transpose the current character and the next character.
ndd Delete the entire current line.
D Delete the rest of the current line (same as d$).
xdnMOT Delete text defined by x multiplied by n motions.

A few examples are:

dL Delete to end of the screen.
dG Delete to end of the buffer.
d1G Delete to the beginning of the buffer.
5dd Delete 5 lines including the current line.

Replacing Text

The following commands are used to replace text. They are not combined with motion commands.

nrc Replace current character with character c.
nR Replace characters forward on current line until Esc pressed; new lines of text may be inserted.

Indenting Text

The following two commands are used to indent and deindent text defined by a certain motion.

x>nMOT Indent text x multiplied by n shiftwidths from current line to position defined by motion MOT.
x<nMOT De-indent text x multiplied by n shiftwidths from current line to position defined by motion MOT.

Filtering Text

Filter commands take the text specified by the motion and send it to a UNIX filter. The text is deleted from the buffer and replaced by the output of the UNIX filter.

!!cmd Send current line to UNIX cmd and replace current line with output of cmd.
n!!cmd Send n lines to UNIX cmd and replace specified n lines with output of cmd.
!nMOTcmd Send n motions of text to standard input of any UNIX filter command to be manipulated and then returned; the original text is replaced. A filter command must be standard input and output capable (e.g., grep, sed, sort, etc.) You DO NOT use a colon for this command.

An example is well worth explaining for this command. Assume you have a screen full of text you need to convert into two columns instead of the one you currently have in the buffer. To do this you just type the following command

     !Lpr -t2

and press Return. The !L command takes all of the text from your cursor to the bottom of the screen and sends it to the pr -t2 command. The pr -t2 command reformats the input text into two-column output. Your screen is redrawn with the same data in two-column format. If you don't like the way it looks, you can always press u for undo.

Moving Text (cut & paste)

By using the y operator you can yank any amount of text based on a motion command. The yank command is referred to as cutting the text in some editors. The p command is used to put the text back in the buffer.

Yanking (cutting)  The text may be yanked to the undo register or to a named register.

nyMOT Yank n motions of text to undo register. Text is copied to register.
ndMOT Delete n motions of text to undo register. Text is copied to register and deleted from buffer.
"regnOPRMOT Perform operator function n motions and store in an alphabetic register ([a-z]). Where \s- 2REG\s+2 is a lowercase letter.
"REGnOPRMOT Perform operator function n motions and append to an alphabetic register ([A-Z]). Where REG is an uppercase letter.

Learning to use the yank command is beneficial if you do much editing. The following examples illustrate how to use the yank command.

5yy Yank five lines to the undo register.
"ayG Yank all lines from the current line to the end of the buffer into register a.

Putting (pasting)

p Put data from undo register after current line.
P Put data from undo register before current line.
REGp Put lines from register REG after current line.
"REGP Put lines from register REG before current line.
"[1-9]p Put 1-9th last delete from corresponding number register.


Previous Table of Contents Next