Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

4 Answers 4

Use the eregex.vim plugin. It's very useful and I have had no problems with it.

share|improve this answer

You can also use:

/\v"your regex"

instead of:

/"your regex"
share|improve this answer

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.