Alphabetical Summary of ex Commands
ex commands can be entered by specifying any unique abbreviation. In this listing, the full name appears in the margin, and the shortest possible abbreviation is used in the syntax line. Examples are assumed to be typed from vi, so they include the : prompt.
abbrev | ab [string text]
Define string when typed to be translated into text. If string and text are not specified, list all current abbreviations. ExamplesNote: ^M appears when you type Ctrl-V followed by Return. : |
append | [address] a[!]
Append text at specified address, or at present address if none is specified. Add a ! to switch the autoindent setting that will be used during input (e.g., if autoindent was enabled, ! disables it). Terminate input by entering a line consisting of just a period. |
args | ar
Print filename arguments (the list of files to edit). The current argument is shown in brackets ([]). |
cd | cd dir
Change current directory within the editor to dir. |
change | [address] c[!]
Replace the specified lines with text. Add a ! to switch the autoindent setting during input of text. Terminate input by entering a line consisting of just a period. |
copy | [address] co destination
Copy the lines included in address to the specified destination address. The command t is the same as copy. Example: |
delete | [address] d [buffer]
Delete the lines included in address. If buffer is specified, save or append the text to the named buffer. Examples: |
edit | e[!] [+n] [file]
Begin editing file. Add a ! to discard any changes to the current file. If no file is given, edit another copy of the current file. With the +n argument, begin editing on linen. Examples: |
exusage | exu [command]
Print a brief usage message describing command, or a list of available commands if command is omitted. |
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. Example: |
global | [address] g[!]/pattern<//[commands]
Execute commands on all lines that contain pattern or, if address is specified, on all lines within that range. If commands are not specified, print all such lines. If ! is used, execute commands on all lines that don't contain pattern. See v. Examples: |
help | h
Print a brief help message. Information on particular commands can be obtained through the exusage and viusage commands. |
insert | address i[!]
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. Terminate input by entering a line consisting of just a period. |
join | [address] j[!] [count]
Place the text in the specified address on one line, with whitespace adjusted to provide two blank characters after a period (.), no blank characters after a ), and one blank character otherwise. Add a ! to prevent whitespace adjustment. Example: |
k | [address] k char
Mark the given address with char. Return later to the line with |
list | [address] l [count]
Print the specified lines so that tabs display as ^I, and the ends of lines display as $. l is a temporary version of :set list. |
map | map[!] [char commands]
Define a keyboard macro named char as the specified sequence of commands. char is usually a single character, or the sequence #n, representing a function key on the keyboard. Use a ! to create a macro for input mode. With no arguments, list the currently defined macros. Examples: |
mark | [address] ma char
Mark the specified line with char, a single lowercase letter. Return later to the line with |
mkexrc | mk[!] file
Create an exrc file containing a set command for every ex option, set to defaults. |
move | [address] m destination
Move the lines specified by address to the destination address. Example: |
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. Add a ! to discard any changes to the current file. Example: |
number | [address] nu [count]
Print each line specified by address, preceded by its buffer line number. Use # as an alternate abbreviation for number. count specifies the number of lines to show, starting with address. |
open | [address] o [/pattern/]
Enter vi's open mode at the lines specified by address or at the lines matching pattern. Enter and exit open mode with Q. Open mode lets you use the regular vi commands, but only one line at a time. May be useful on slow dial-up lines. |
preserve | pre
Save the current editor buffer as though the system had crashed. |
previous | prev[!]
Edit the previous file from the command-line argument list. |
[address] p [count]
Print the lines specified by address. count specifies the number of lines to print, starting with address. Add a ! to discard any changes to the current file. Example: | |
put | [address] pu [char]
Restore the lines that were previously deleted or yanked from named buffer char, and put them after the line specified by address. If char is not specified, restore the last deleted or yanked text. |
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 were never accessed, quit by typing q! or by typing q twice. |
read | [address] r file
Copy in the text from file on the line below the specified address. If file is not specified, the current filename is used. Example: |
read | [address] r !command
Read the output of Linux command into the text after the line specified by address. Example: |
recover | rec [file]
Recover file from system save area. |
rewind | rew[!]
Rewind argument list and begin editing the first file in the list. The ! flag rewinds, discarding any changes to the current file that haven't been saved. |
script | sc[!] [file]
Create a new shell in a buffer that can be saved, optionally specifying file where the buffer can be saved. Can be used only in vi. |
set | se parameter1 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 Boolean-valued options, each parameter can be phrased as option or nooption; other options can be assigned with the syntax option=value. Specify all to list current settings. Examples: |
shell | sh
Create a new shell. Resume editing when the shell is terminated. |
source | so file
Read and execute ex commands from file. Example: |
stop | st
Suspend the editing session. Same as Ctrl-Z. Use fg to resume session. |
substitute | [address] s [/pattern/replacement/] [options] [count]
Replace each instance of pattern on the specified lines with replacement. If pattern and replacement are omitted, repeat last substitution. count specifies the number of lines on which to substitute, starting with address. When preceded by the global (g) or v command, this command can be specified with a blank pattern, in which case the pattern from the g or v command is then used. For more examples, see "Examples of Searching and Replacing" in "Pattern Matching". Options
Examples: |
suspend | su
Suspend the editing session. Same as Ctrl-Z. Use fg to resume session. |
t | [address] t destination
Copy the lines included in address to the specified destination address. t is an alias for copy. Example: |
tag | [address] ta[!] tag
Switch the editing session to the file containing tag. ExampleRun ctags, then switch to the file containing myfunction: : |
tagnext | tagn[!] |
tagpop | tagp[!]
Forget the current tag and return to the last position of the previous tag found. |
tagprev | tagpr[!] |
tagtop | tagt[!]
Return to the first tag searched for and forget about all tags. |
unabbreviate | una word |
undo | u
Reverse the changes made by the last editing command. |
unmap | unm[!] char
Remove char from the list of keyboard macros. Use ! to remove a macro for input mode. |
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!. See global. Example: |
version | ve
Print the editor's current version number. |
vi | vi [+n] file
Begin editing file, optionally at line n. Can be used only in vi. |
visual | [address] vi [type] [count]
Enter visual mode (vi) 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. |
viusage | viu [key]
Print a brief usage message describing the operation of key, or a list of defined keys if key is omitted. |
wq | wq[!]
Write and quit the file in one command. The ! flag forces the editor to write over any current contents of file. |
write | [address] w[!] [[>>] file
Write lines specified by address to file, or write full contents of buffer if address is not specified. If file also is omitted, save the contents of the buffer to the current filename. If >>file is used, write contents to the end of an existing file. The ! flag forces the editor to write over any current contents of file. |
write | [address] w !command
Write lines specified by address to command. Examples: |
xit | x
Write the file if it was changed since the last write, then quit. |
yank | [address] ya [char] [count]
Place lines specified by address in named buffer char. If no char is given, place lines in general buffer. count specifies the number of lines to yank, starting with address. Example: |
z | [address] z [type] [count]
Print a window of text, with the line specified by address at the top. count specifies the number of lines to be displayed. Type
|
! | [address] !command
Execute Linux 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. Examples: |
= | [address] =
Print the line number of the next line matching address. If no address is given, print the number of the last line. |
< > | [address]<[count]
Shift lines specified by address either left (<) or right (>). Only blanks and tabs are removed in a left shift. count specifies the number of lines to shift, starting with address. |
address | address
Print the line specified in address. |
Return | Return
Print the next line in the file. |
& | & [options] [count]
Repeat the previous substitution (s) command. count specifies the number of lines on which to substitute, starting with address. Examples: |
~ | [address] ~ [count]
Replace the previous regular expression with the previous replacement pattern from a substitute (s) command. |
^D | ^D
Scroll through the file. |
^Z | ^Z
Suspend the editing session. Use fg to resume session. |