Learning the vi Editor

Learning the vi EditorSearch this book
Previous: C.1 Command Syntax Appendix C
ex commands
Next: D. Problem Checklist
 

C.2 Alphabetical List of Commands

In this section, the full name of the ex command is listed as the keyword. To the right of each keyword is the syntax, using the shortest abbreviation possible for that command. A brief description follows the syntax.

abbrev

ab [string text]

Define string when typed to be translated into text. If string and text are not specified, list all current abbreviations.

append

[address] a[!]

text

.

Append text at specified address, or at present address if one is specified. Add a ! to switch the autoindent setting that will be used during input. That is, if autoindent was enabled, ! disables it.

args

ar

Print the members of the argument list, with the current argument printed within brackets ([ ]).

change

[address] c[!]

text

.

Replace the specified lines with text. Add a ! to switch the autoindent setting during input of text.

copy

[address] co destination

Copy the lines included in address to the specified destination address. The command t is a synonym for copy.

delete

[address] d [buffer]

Delete the lines included in address. If buffer is specified, save or append the text to the named buffer.

edit

e [!][+n] [filename]

Begin editing on filename. If no filename is given, bring in another copy of the current file. Add a ! to edit the new file even if the current file has not been saved since the last change. With the +n argument, begin editing on line n.

file

f[filename]

Change the name of the current file to filename, which is considered "not edited". If no filename is specified, print the current status of the file.

global

[address]g[!]/pattern/[commands]

Execute commands on all lines which contain pattern, or if address is specified, all lines within that range. If commands are not specified, print all such lines. Add a ! to execute commands on all lines not containing pattern.

insert

[address] i[!]

text

.

Insert text at line before the specified address, or at present address if none is specified. Add a ! to switch the autoindent setting during input of text.

join

[address] j[!] [count]

Place the text in the specified range on one line, with white space adjusted to provide two blank characters after a period (.), no blank characters after a ), and one blank character otherwise. Add a ! to prevent white space adjustment.

k

[address] k char

Mark the given address with char. Return later to the line with 'x.

list

[address] l [count]

Print the specified lines so that tabs display as ^I and the ends of lines display as $.

map

map char commands

Define a macro named char in visual mode with the specified sequence of commands. char is usually a single character, or the sequence #n, representing a function key on the keyboard.

mark

[address] ma char

Mark the specified line with char, a single lowercase letter. Return later to the line with 'x.

move

[address] m destination

Move the lines specified by address to the destination address.

next

n[!] [[+command] filelist]

Edit the next file from the command-line argument list. Use args to list these files. If filelist is provided, replace the current argument list with filelist and begin editing on the first file; if command is given (containing no spaces), execute command after editing the first such file.

number

[address] nu [count]

Print each line specified by address, preceded by its buffer line number. Use # as an alternate abbreviation for number.

open

[address] o [/pattern/]

Enter open mode (vi) at the lines specified by address, or at the lines matching pattern. Exit open mode with Q.

preserve

pre

Save the current editor buffer as though the system had crashed.

print

[address] p[ count]

Print the lines specified by address. P is another abbreviation.

put

[address] pu [char]

Restore previously deleted or yanked lines, from named buffer specified by char, to the line specified by address; if char is not specified, the last deleted or yanked text is restored.

quit

q[!]

Terminate current editing session. Use ! to discard changes made since the last save. If the editing session includes additional files in the argument list that have not yet been accessed, quit by typing q! or by typing q twice.

read

[address] r filename

Copy the text of filename at the specified address. If filename is not specified, the current filename is used.

read

[address] r ! command

Read in the output of command into the text after the line specified by address.

recover

rec [filename]

Recover filename from system save area.

rewind

rew[!]

Rewind argument list and begin editing the first file in the list. Add a ! to rewind even if the current file has not been saved since the last change.

set

se parameter parameter2

Set a value to an option with each parameter, or if no parameter is supplied, print all options that have been changed from their defaults. For toggle options, each parameter can be phrased as "option" other options can be assigned with the syntax, "option=value"

shell

sh

Create a new shell. Resume editing when the shell is terminated.

source

so filename

Read and execute commands from filename.

substitute

[address] s [/pattern/repl/][options]

Replace each instance of pattern on the specified lines with repl. If pattern and repl are omitted, repeat last substitution. An option of g substitutes all instances of pattern on the line. An option of c prompts for confirmation before each change.

t

[address]tdestination

Copy the lines included in address to the specified destination address. t is an alias for copy.

tag

[address] ta tag

Switch the focus of editing to tag.

unabbreviate

una word

Remove word from the list of abbreviations.

undo

u

Reverse the changes made by the last editing command.

unmap

unm char

Remove char from the list of macros.

v

[address] v/ pattern/[commands]

Execute commands on all lines not containing pattern. If commands are not specified, print all such lines. v is equivalent to g!.

version

ve

Print the current version number of the editor and the date the editor was last changed.

visual

[address] vi [type] [count]

Enter visual mode at the line specified by address. Exit with Q. type can be one of -, ^, or \. (See the z command). count specifies an initial window size.

visual

vi [+n] [filename]

Begin editing on filename in visual mode.

write

[address] w[!] [[>>]filename]

Write lines specified by address to filename, or full contents of buffer if address is not specified. If filename is also omitted, save the contents of the buffer to the current filename. If >> filename is used, write contents to the end of the specified filename. Add a ! to force the editor to write over any current contents of filename.

write

[address] w !command

Write lines specified by address to command.

wq

wq[!]

Write and quit the file in one movement.

xit

x

Write file if changes have been made to the buffer since last write, then quit. x is equivalent to wq.

yank

[address] ya [char] [count]

Place lines specified by address in named buffer indicated by char, or if no char is specified place in general buffer.

z

[address z [type] [count]

Print a window of text with line specified by address at the top. type can be one of:

+

Place specified line at the top of the window (default).

-

Place specified line at bottom of the window.

.

Place specified line in the center of the window.

^

Print the previous window.

=

Place specified line in the center of the window and leave the current line at this line. count specifies the number of lines to be displayed.

countspecifies the number of lines to be displayed.

!

[address] !command

Execute command in a shell. If address is specified, apply the lines contained in address as standard input to command, and replace the lines with the output.

=

[address] =

Print the line number of the line indicated by address.

<>

[address] < [count]

or

[address] > [count]

Shift lines specified by address in specified direction. Only blanks and tabs are shifted in a left-shift (<).

address

address

Print the lines specified in address.

RETURN

RETURN

Print the next line in the file.

&

[address] & [options] [count]

Repeat the previous substitute command.

~

[address]~[count]

Replace the previous regular expression with the previous replacement pattern from a substitute command.


Previous: C.1 Command Syntax Learning the vi EditorNext: D. Problem Checklist
C.1 Command Syntax Book IndexD. Problem Checklist

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System