home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Linux in a NutshellLinux in a NutshellSearch this book

11.14. 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.

read

[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
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 used. For more examples, see Chapter 9.

Options

c
Prompt for confirmation before each change.

g
Substitute all instances of pattern on each line.

p
Print the last line on which a substitution was made.

Examples

1,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
write

[address] w !command

Write lines specified by address to command.

Examples

1,10w name_list      Copy first 10 lines to name_list
:50w >> name_list     Now append line 50
@@

[address] @

Repeat the last @ command. If address is given, move cursor to the specified address first. {vim}

~

[address] ~ [count]

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



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.