Can I use perl regular expressions in the vim command line?

I want to use perl regular expressions on the vim command line. For example, to capitalize the words on the current line, you could type:

:s/(\w+)/\u$1/g

You can filter any line or range of lines through an external command in vim, using !. E.g., you can do:

:.!perl -pe "s/(\w+)/\u\1/g"

which will filter the current line through that perl command. ( Here : to get into command line mode, and the . which follows mean the current line; you can also specify a line range or % for the whole file, etc.)

If you want to use vim's built in substitution patterns, the closest you'll come is to use vim's "very magic" option, \v, like so:

:s/\v(\w+)/\u\1/g

see :help pattern and :help substitute for more details. I don't think "very magic" is quite identical to perl's patterns, but is very close. Anyway, you can always use perl itself if you're more comfortable with it, as above.


No, you can't use Perl regular expressions in that way. For help in learning the Vim equivalents for Perl regular expression components, see

:help perl-patterns

However, you can use Perl as an external filter as explained by frabjous. You can also execute Perl commands within Vim using the Perl interface, if your Vim was compiled with the +perl feature. See

:help if_perl.txt