Editing files

Moving around a file

To move the cursor a single character in any direction, use the arrow keys. Alternatively, if you are in command mode, you can use the following keys:

move left one character

move right one character

move up one line

move down one line
You can also move around in larger units than a single character. To repeat any of the following movement commands (that take an optional parameter n) type the number of times you wish the command to occur followed by the command. For example, to move right five words, enter 5w:

move back one (or n) words

move forward one (or n) words

move to the start of the line

move to the end of the line

move back one (or n) sentences

move forward one (or n) sentences

move back one (or n) paragraphs

move forward one (or n) paragraphs
(vi considers a sentence to be a sequence of characters ending with a dot, question mark, or exclamation mark, followed by either two spaces or a newline. Sentences begin on the first nonwhitespace character following a preceding sentence, and are delimited by paragraph and section delimiters. A paragraph is any block of text delimited by empty lines or an nroff formatter macro.)

Other commands control the portion of the file that the screen displays:

move back half a screen

move forward half a screen

move back one screen

move forward one screen
You can specify line numbers to set your position within a file.

To discover the current line number, press <Ctrl>G. A status line appears at the bottom of the screen, telling you the name of the file, whether it has been modified, your current line number, the number of lines in the file, and your position in the file as a percentage of the length of the file. For example:

"soliloquy" [Modified] line 24 of 35 --68%--

To make line numbers appear at the left-hand side of the screen, enter :set number (the numbers are not added to the text of your file). To make vi always display line numbers, you can add this command to your .exrc file. See ``Configuring vi'' for more information.

The following commands move you to a specified line number:

go to line number #

go to the start of a file

go to the end of a file (equivalent to $G)
For details of the many other movement commands available see the vi(C) manual page.
Next topic: Deleting and restoring text
Previous topic: Saving files and quitting vi

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003