Previous Table of Contents Next


Limits

The vi editor has some limits that you may need to know. These limits control how vi functions. They may vary from manufacturer to manufacturer.

The following table lists the maximum allowed limits.


Maximum Description

512 or 1024 Characters on one line.
250,000 Lines per file (buffer).
128 Characters per filename.
30 Characters in a tag name.
256 Characters in a global command list.
128 Characters in previous insert or delete in vi.
100 Characters in UNIX escape command.
32 Total string macros (map macros).
512 Total characters in string macros.


NOTE:  
The number of tag file entries appear unlimited. However, if you use single-digit tags the first ten tags are often misinterpreted or not understood at all.



MOTION COMMANDS

Motion Commands allow you to move around the file in units of text. You must be in Command mode to use the motion commands. Refer to the section on Units for definitions of text. You can return to Command mode from any other mode by pressing Esc.

vi is in Command mode after invocation. vi interprets keystrokes and then performs the action. Some of the motion commands may be preceded by a number to repeat the command a number of times. In the following descriptions the n signifies that multiple repetitions of the command may be specified. In most cases n defaults to 1 if you do not specify a number. Not all versions support multiplicity on all commands.

Line 1 of the file is considered the top of the buffer; therefore, backward, up, and previous refer to moving towards the top of the buffer (line 1). Likewise, forward, down, and next refer to moving towards the bottom of the buffer (last line). If the bell "beeps," then you are at a buffer boundary or the command is not valid.

Character Movement

There are four commands to move forward and backward by a character unit.

nh Move backward n characters.
 n<bs>
nl Move forward n characters.
 n<sp>
To move right one character press an l or Right Arrow; to move left one character press an h or Left Arrow.

Word Movement

There are six commands used for moving by words. A word is defined as any set of characters delimited by a tab, space, or new-line.

nw Move forward to the beginning of the nth word.
nW Move forward to the beginning of the nth word, ignoring punctuation.
ne Move forward to the end of the nth word.
nE Move forward to the end of the nth word, ignoring punctuation.
nb Move backward to the beginning of the nth previous word.
nB Move backward to the beginning of the nth previous word, ignoring punctuation.

Line Movement

There are eight line-oriented commands. A line is defined as beginning at the left side of the screen and ending with a carriage return (octal 15). A physical line may wrap around the screen and create what appears to be multiple lines.

Vertical Movement allows you to move from line to line.

nj Move forward (down) n lines and keep the cursor in the same column.
 nCtrl-N
nk Move backward (up) n lines and keep the cursor in the same column.
 nCtrl-P
n+ Move to beginning of text on the next line.
 n<cr>
n- Move to beginning of text on the previous line.

Horizontal Movement allows you to change positions on the current line.

0 Move to beginning of current line (zero).
n$ Move to end of current line.
^ Move to beginning of text on the current line.
_
n| Move to column n. If n is not given then move to beginning of current line.

Sentence

There are two commands for moving by sentences. A sentence refers to the English grammar version of a sentence ending with punctuation.

n) Move to beginning of next sentence.
n( Move to beginning of previous sentence.

Paragraph

There are two commands for moving by paragraphs. A paragraph ends with a Memorandum Macro Paragraph token or a blank line.

n} Move to beginning of next paragraph.
n{ Move to beginning of previous paragraph.

Section

There are two commands for moving by section. A section ends with a Memorandum Macro Header token (.H) or an open or close brace ({}) in C program text.

n]] Move to beginning of next section or function.
n[[ Move to beginning of previous section or function.

Screen

There are three commands that allow you to move around based on the displayed screen.

nH High point (home; top left corner) of screen. Move cursor to the beginning of first (top) line displayed on the screen.
M Middle point (middle line) of screen. Move cursor to beginning of middle line displayed on the screen.
nL Low point (bottom left corner) of screen. Move cursor to beginning of last line displayed on the screen.

The following examples illustrate the various screen movement commands.

5H Locate the cursor 5 lines below the top of the screen.
L Locate the cursor on the last line of the screen.

Character Search by Line

You can use one of the following six commands to search for a particular character on the current line. If no character is found, then vi displays a video bell or beeps at you.

nfc Search forward on current line to character c in text.
nFc Search backward on current line to character c in text.
ntc Search forward on current line to position before character c.
nTc Search backward on current line to position after character c.
n; Repeat last f, F, t, or T.
n, Inverse direction of last ; command.

The following examples help clarify the use of the character search commands.

ft Search for the first occurrence of t on the current line.
Fx Search backward for the previous occurrence of the letter x.
; Search backward for the next occurrence of x.

String Search

String searches are used to locate an occurrence of a specific string. Regular expressions may be used to help locate various different strings using the same search pattern. When you type the slash (/) your cursor jumps to the bottom left corner of your screen. At this point enter the pattern you wish to search for in the buffer.

n/pat Search forward for the string matching pat.
n?pat Search backward for the string matching pat.
n/pat/+x Search forward for the string matching pat, then move forward (down) x lines.
n?pat?+x Search backward for the string matching pat, then move forward (down) x lines.
n/pat/-x Search forward for the string matching pat, then move backward (up) x lines.
n?pat?-x Search backward for the string matching pat, then move backward (up) x lines.
nn Repeat last / or ?, n times in same direction.
nN Reverse the direction of last / or ?, repeat n times.
n// Search for nth match of last pattern.
; Search command separator.
/pat1/;/pat2/ Search for pat2 after finding pat.

The following examples illustrate the use of the search command. End each search pattern by pressing Return. If a pattern match is located, the cursor is positioned at the new location. If no string is located, vi notifies you as such.

/Myname Searches for the literal string "Myname."
/[A-Z0-9] Searches for an uppercase letter or a number.
/^[^Ctrl-I] Searches for a line that does not begin with a tab (Ctrl-I).
/^$ Search for blank (empty) lines.

Marking and Returning

" Move to prior location in buffer, beginning of line. Functional only after text manipulation or a motion command is performed.
" Move to prior location in buffer, exact character position on line. Functional only after text manipulation or a motion command is performed.
mc Mark current cursor position with character c. Valid characters for c are a-z. The mark is invisible, no character or reverse video features are provided.
'c Move to the beginning of the line marked by character c (see mc). Includes last line of defined text when used with an operator.
'c Move to the exact position marked by character c (see mx). Excludes last line of defined text when used with an operator.

Buffer Movement

These following six commands are used to scroll the buffer forward or backward to display a new screen or to jump to a specific line and display a new screen.

Scrolling

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.

NOTE:  
The Ctrl-F, Ctrl-B, Ctrl-D, and Ctrl-U commands are not true motion commands and cannot be used in conjunction with an operator.



Go to Location  There are two ways to move to specific locations in the buffer. One is by line number, the other is by symbolic tags.

nG Go to line n. If n is not given then cursor is moved to last line of the buffer (file).
^] Go to tag described in next word, refer to section on Tags.

Screen Adjusting

nCtrl-E Scroll window forward (down) 1 line.
nCtrl-Y Scroll window backward (up) 1 line.
Ctrl-L Redraw screen (cleans garbled screen).
Ctrl-R Redraw the screen removing all lines with @ signs. Dumb terminals cannot remove deleted lines from the display and thus vi places an @ sign on the line to signify that it has been deleted. Ctrl-R redraws the screen, removing all of these deleted lines.
z Redraw, place the current line at top of the window.
z. Redraw, place the current line at the middle of the window.
z- Redraw, place the current line at the bottom of the window.
n/pat/z Redraw, place the line with pat at top of window.
n/pat/z. Redraw, place the line with pat at middle of window.
n/pat/z- Redraw, place the line with pat at bottom of window.
zn. Redraw, use n line window.

NOTE:  
"Window" refers to the current window size, which may or may not be the entire physical screen. The window size expands until the screen size is reached as the cursor is moved outside the window limits. Different terminal types cause different actions to occur when screen manipulation is performed.




Previous Table of Contents Next