Book HomeLearning the vi EditorSearch this book

12.7. Extended Regular Expressions

Extended regular expressions were introduced in Section 8.4. vile provides essentially the same facilities as nvi's extended option. The syntax is somewhat different though, relying upon additional backslash-escaped characters:

\|
Indicates alternation, house\|home.

\+
Matches one or more of the preceding regular expression.

\?
Matches zero or one of the preceding regular expression.

\(...\)
Provides grouping for *, \+, and \?, as well as making matched sub-texts available in the replacement part of a substitute command (\1, \2, etc.).

\s \S
Match whitespace and non-whitespace characters, respectively.

\w \W
Match "word-constituent" characters (alphanumerics and the underscore, `_') and non-word-constituent characters, respectively. For example, \w\+ would match C/C++ identifiers and keywords.[60]

[60]For the pedantic among you, it also matches identifiers that start with a leading digit; usually this isn't much of a problem.

\d \D
Match digits and non-digits, respectively.

\p \P
Match printable and non-printable characters respectively. Whitespace is considered to be printable.

vile allows the escape sequences \b, \f, \r, \t, and \n to appear in the replacement part of a substitute command. They stand for backspace, formfeed, carriage return, tab and newline, respectively. Also, from the vile documentation:

Note that vile mimics perl's handling of \u\L\1\E instead of vi's. Given :s/\(abc\)/\u\L\1\E/ vi will replace with abc whereas vile and perl will replace with Abc. This is somewhat more useful for capitalizing words.

Example .vilemenu File

# lines beginning with 'C' define a menu heading
C:Xvile
# the following four entries are Buttons invoking menu
# system builtins
B:New:new_xvile
B:Edit .vilerc:edit_rc
B:Parse .vilerc:parse_rc
B:Edit .vilemenu:edit_mrc
B:Quit:quit
#
C:Editing
B:Search Forward...:cmd search-forward
B:Search Backward...:cmd search-reverse
# lines beginning with S are separators
S
B:Manual for...:29
S
# where the command to be executed is given as a number, like the
#  two above and the three below, the menu system will translate
#  this to an invocation of the command execute-macro-<number>.
B:Indent Level...:31
B:Window Title...:35
B:Font...:36
#
C:Buffers
# run a command name (in this case "toggle-buffer") by simply
# naming it
B:Toggle Show:toggle-buffer
# one line starting with 'L' is allowed, at the end of a menu --
# it causes a buffer list menu to be created.
L:list_buff
#
C:Fonts
B:5x8:setv $font 5x8
B:7x14:setv $font 7x14
B:8x13:setv $font 8x13
B:8x16:setv $font 8x16
B:9x15:setv $font 9x15
B:10x20:setv $font 10x20
B:12x24:setv $font 12x24
#
C:Attributes
B:C/C++:30
B:Pascal:32
C:Help:help
B:About:version
S
B:General:help
B:Bindings:describe-bindings
B:Motions:describe-motions
B:Operators:describe-operators
S
# prefixing a command with "cmd" will force it to be run as from
#  the ':' line, so that it can prompt for input correctly.
B:Apropos...:cmd apropos
B:Apropos...:apropos set
B:On Function...:cmd describe-function
B:On Key...:describe-key &gts
S
B:Settings:setall
B:Variables:show-variables
B:Registers:show-registers



Library Navigation Links

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