Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

share|improve this question

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:


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

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
+1, :help perl-patterns has resolved the one thing that I previously hated about vim – Mark K Cowan Aug 26 '14 at 16:57

You can also use:

/\v"your regex"

instead of:

/"your regex"
share|improve this answer

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

share|improve this answer

Here's a solution from

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

(Verify with :ver that +perl or +perl/dyn is compiled in.)

share|improve this answer

Your Answer


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.