11.14. Alphabetical Summary of ex Commandsex 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.
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. :ab ora O'Reilly & Associates, Inc. :ab id Name:^MRank:^MPhone:
[address] a[!] Append new 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). Enter new text after entering the command. Terminate input of new text by entering a line consisting of just a period. Examplea Begin appending to current line. Append this line and this line too. . Terminate input of text to append.
ar Print filename arguments (the list of files to edit). The current argument is shown in brackets ([ ]).
[n] bd[!] [n] Unload buffer n and remove it from the buffer list. Add a ! to force removal of an unsaved buffer. The buffer may also be specified by filename. If no buffer is specified, remove the current buffer. {vim}
[n] b[!] [n] Begin editing buffer n in the buffer list. Add a ! to force a switch from an unsaved buffer. The buffer may also be specified by filename. If no buffer is specified, continue editing the current buffer. {vim}
buffers[!] Print the listed members of the buffer list. Some buffers (e.g., deleted buffers) will not be listed. Add ! to show unlisted buffers. ls is another abbreviation for this command. {vim}
[address] ce [width] Center line within the specified width. If width is not specified, use textwidth. {vim}
[address] c[!] text 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.
clo[!] Close current window unless it is the last window. If buffer in window is not open in another window, unload it from memory. This command will not close a buffer with unsaved changes, but you may add ! to hide it instead. {vim}
[address] co destination Copy the lines included in address to the specified destination address. The command t is the same as copy. Example1,10 co 50 Copy first 10 lines to just after line 50
[address] d [buffer] Delete the lines included in address. If buffer is specified, save or append the text to the named buffer. Examples/Part I/,/Part II/-1d Delete to line above "Part II" :/main/+d Delete line below "main" :.,$d Delete from this line to last line
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 line n. Examplese file :e# Return to editing the previous file :e! Discard edits since last save
exu [command] Print a brief usage message describing command, or a list of available commands if command is omitted. (In vim use the help command instead.)
f [filename] Change the filename for the current buffer to filename. The next time the buffer is written, it will be written to file filename. When the name is changed, the buffer's notedited flag is set, to indicate you are not editing an existing file. If the new filename is the same as a file that already exists on the disk, you will need to use :w! to overwrite the existing file. When specifying a filename, the % character can be used to indicate the current filename. If no filename is specified, print the current name and status of the buffer. Examplef %.new
address fo Fold the lines specified by address. A fold collapses several lines on the screen into one line, which can later be unfolded. It doesn't affect the text of the file. {vim}
[address] foldc[!] Close folds in specified address, or at present address if none is specified. Add a ! to close more than one level of folds. {vim}
[address] foldo[!] Open folds in specified address, or at present address if none is specified. Add a ! to open more than one level of folds. {vim}
[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. Examplesg/Unix/p Print all lines containing "Unix" :g/Name:/s/tom/Tom/ Change "tom" to "Tom" on all lines containing "Name:"
h Print a brief help message. Information on particular commands can be obtained through the exusage and viusage commands. (In vim this command provides extensive information for all commands, and neither exusage nor viusage is used.)
hid Close current window unless it is the last window, but do not remove the buffer from memory. This is a safe command to use on an unsaved buffer. {vim}
address i[!] Insert new 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. Enter new text after entering the command. Terminate input of new text by entering a line consisting of just a period.
[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. Example1,5j! Join first five lines, preserving whitespace
ju Print jump list used with Ctrl-I and Ctrl-O commands. The jump list is a record of most movement commands that skip over multiple lines. It records the position of the cursor before each jump. {vim}
[address] l [count] Print the specified lines so that tabs display as ^I, and the ends of lines display as $. The l command is a temporary version of :set list.
[address] le [count] Left-align lines specified by address, or current line if no address is specified. Indent lines by count spaces. {vim}
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. Examplesmap K dwwP Transpose two words :map q :w^M:n^M Write current file; go to next :map! + ^[bi(^[ea) Enclose previous word in parentheses
[address] ma char Mark the specified line with char, a single lowercase letter. Return later to the line with 'char. vim also uses uppercase and numeric characters for marks. Lowercase letters work the same as in vi. Uppercase letters are associated with filenames and can be used between multiple files. Numbered marks, however, are maintained in a special viminfo file and cannot be set using this command. Same as k.
marks [chars] Print list of marks specified by chars, or all current marks if no chars specified. {vim} Examplemarks abc Print marks a, b and c.
[address] m destination Move the lines specified by address to the destination address. Example.,/Note/m /END/ Move text block after line containing "END"
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. Examplen chap* Start editing all "chapter" files
noh Temporarily stop highlighting all matches to a search when using the hlsearch option. Highlighting is resumed with the next search. {vim}
[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.
[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. [address] p [count] [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. Example100;+5p Show line 100 and the next 5 lines
[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.
qa[!] Close all windows and terminate current editing session. Use ! to discard changes made since the last save. {vim}
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. (In vim, if multiple windows are open, this command will close only the current window; use qall to quit multiple windows.)
[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. Example0r $HOME/data Read file in at top of current file
[address] r !command Read the output of Linux command into the text after the line specified by address. Example$r !cal Place a calendar at end-of-file
res [[+|-]n] Resize current window to be n lines high. If + or - is specified, increase or decrease the current window height by n lines. {vim}
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.
[address] le [width] Right-align lines specified by address, or current line if no address is specified, to column width. Use textwidth option if no width is specified. {vim}
[n] sb [n] Split the current window and begin editing buffer n from the buffer list in the new window. The buffer to be edited may also be specified by filename. If no buffer is specified, open the current buffer in the new window. {vim}
[count] sbn [count] Split the current window and begin editing the count next buffer from the buffer list. If no count is specified, edit the next buffer in the buffer list. {vim}
[count] sn [[+n] filelist] Split the current window and begin editing the next file from the command-line argument list. If count is provided, edit the count next file. If filelist is provided, replace the current argument list with filelist and begin editing the first file. With the +n argument, begin editing on line n. Alternately, n may be a pattern of the form /pattern. {vim}
[count] sp [+n] [filename] Split the current window and load filename in the new window, or the same buffer in both windows if no file is specified. Make the new window count lines high, or if count is not specified, split the window into equal parts. With the +n argument, begin editing on line n. n may also be a pattern of the form /pattern. {vim}
[count] spr [+n] Split the current window and begin editing the previous file from the command-line argument list in the new window. If count is specified, edit the count previous file. With the +n argument, begin editing on line n. n may also be a pattern of the form /pattern. {vim}
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.
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. Examplesset nows wm=10 :set all
[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 used. For more examples, see Chapter 9. Options
Examples1,10s/yes/no/g Substitute on first 10 lines :%s/[Hh]ello/Hi/gc Confirm global substitutions :s/Fortran/\U&/ 3 Uppercase first instance of "Fortran" on next three lines :g/^[0-9][0-9]*/s//Line &:/ For every line beginning with one or more digits, add the "Line" and a colon
[count] sv [+n] [filename Same as the split command, but set the readonly option for the new buffer. {vim}
[address] t destination Copy the lines included in address to the specified destination. t is an alias for copy. Example%t$ Copy the file and add it to the end
[address] ta[!] tag Switch the editing session to the file containing tag. ExampleRun ctags, then switch to the file containing myfunction: :!ctags *.c :tag myfunction
u Reverse the changes made by the last editing command. In vi the undo command will undo itself, redoing what you undid. vim supports multiple levels of undo. Use redo to redo an undone change in vim.
[count] unh Split screen to show one window for each active buffer in the buffer list. If specified, limit the number of windows to count. {vim}
unm[!] char Remove char from the list of keyboard macros. Use ! to remove a macro for input mode.
[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. Examplev/#include/d Delete all lines except "#include" lines
vie[[+n] filename] Same as edit, but set file to readonly. When executed in ex mode, return to normal or visual mode. {vim}
[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.
viu [key] Print a brief usage message describing the operation of key, or a list of defined keys if key is omitted. (In vim use the help command instead.)
[count] vs [+n] [filename] Same as the split command, but split the screen vertically. The count argument can be used to specify a width for the new window. {vim}
wa[!] Write all changed buffers with filenames. Add ! to force writing of any buffers marked readonly. {vim}
[count] wn[!] [[+n] filename] Write current buffer and open next file in argument list, or the count next file if specified. If filename is specified, edit it next. With the +n argument, begin editing on line n. n may also be a pattern of the form /pattern. {vim}
wq[!] Write and quit the file in one command. The ! flag forces the editor to write over any current contents of file.
wqa[!] Write all changed buffers and quit the editor. Add ! to force writing of any buffers marked readonly. xall is another alias for this command. {vim}
[address] w[!] [[>>] file] Write lines specified by address to file, or write full contents of buffer if address is not specified. If file is also 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.
[address] w !command Write lines specified by address to command. Examples1,10w name_list Copy first 10 lines to name_list :50w >> name_list Now append line 50
X Prompt for an encryption key. This can be preferable to :set key as typing the key is not echoed to the console. To remove an encryption key, just reset the key option to an empty value. {vim}
[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. Example101,200 ya a
[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!ls List files in the current directory :11,20!sort -f Sort lines 11-20 of current file
[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] [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] @ [char] Execute contents of register specified by char. If address is given, move cursor to the specified address first. Both star and * are aliases for this command. {vim}
[address] @ Repeat the last @ command. If address is given, move cursor to the specified address first. {vim}
& [options] [count] Repeat the previous substitution (s) command. count specifies the number of lines on which to substitute, starting with address. Exampless/Overdue/Paid/ Substitute once on current line :g/Status/& Redo substitution on all "Status" lines
[address] ~ [count] Replace the previous regular expression with the previous replacement pattern from a substitute (s) command. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|