Learning the vi Editor

Learning the vi EditorSearch this book
Previous: 12.6 GUI InterfacesChapter 12
vile -- vi Like Emacs
Next: 12.8 Improved Editing Facilities

12.7 Extended Regular Expressions

Extended regular expressions were introduced in Section 8.4, "Extended Regular Expressions" in Chapter 8. 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.[3]

[3] 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.

Previous: 12.6 GUI InterfacesLearning the vi EditorNext: 12.8 Improved Editing Facilities
12.6 GUI InterfacesBook Index12.8 Improved Editing Facilities

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