This is a read-only archive!

Vim regexes

One thing I very much miss in Gentoo is controlling what is compiled into my Vim. You need to enable perldo and rubydo support at compiletime. Gentoo had USE flags to do it. In Ubuntu I get perldo but no rubydo by default, which is annoying.

The reason I need perldo/rubydo is because Vim's regexes are so inconsistent. * is special when not escaped, but + is special when escaped. You can use \{x,y} (escape only opening bracket), but you have to use \( \) (escape both parens), and with [] it's special when you don't escape either. I simply can't remember these, especially when coding at full speed, and speed is one of the reasons to use Vim in the first place.

Then Vim has magic and nomagic. And you can use \v to set "very magic". Very magic is almost what I want, but you can't set it in your .vimrc and even if you could, the Vim manual tells you to leave the setting of magic alone if you know what's good for you.

PCREs are so much more consistent and easier to remember (excepting Perlisms like "dot matches newline" inconsistencies). The special characters are always special, and you escape them all to make them non-special. But perldo and rubydo in Vim can't do everything Vim regexes can do; they can't properly span lines, is the major thing. They don't highlight text like Vim does with its builtin regexes if you have hls set.

I read somewhere that Vim regexes are set up to let you match C code easily, and that's why for example {} are non-special by default. I don't remember where I read it or if it's true. Doesn't help a lot when writing non-C code though.

March 05, 2007 @ 11:43 AM PST
Cateogory: Programming
Tags: Perl, Ruby, Vim, Gentoo


Quoth chi on March 05, 2007 @ 12:52 PM PST

I know exactly what you mean. I am currently trying to write my own syntax highlighting script for a certain wiki syntax and have the pattern help pages opened all the time because I often cant remember what needs to be escaped within vim regexes an what not. "help: perl-patterns" gives a - lets say "little short" explanation about their differences, but I guess it`s better not to get used to vim regexes - could lead to confusion in other places.

Quoth numerodix on March 06, 2007 @ 5:36 AM PST

Hey Brian, I'm new to vim... how do I unset stuff? :set list ayeeee how do I unset this?

Quoth Brian on March 06, 2007 @ 10:43 AM PST

:set nolist. Generally there's a :set command and :set nocommand pair.

Quoth numerodix on March 07, 2007 @ 1:32 AM PST

Thanks. Another one for you. How do I allow the humble cursor to move beyond the last character of a line in command mode? He really would love to, but he's not allowed there. :(

Quoth Brian on March 07, 2007 @ 2:59 AM PST

I don't think you can. Generally to enter text at the end of a line I hit A (capital A, note). Not sure what other reason there would be to move the cursor beyond the text like that.

Armin Ronacher
Quoth Armin Ronacher on April 04, 2007 @ 10:00 AM PDT

apt-get install vim-ruby

Quoth Brian on April 09, 2007 @ 2:38 PM PDT

vim-ruby does not seem to enable rubydo. Dunno.

Mary Vieira
Quoth Mary Vieira on November 01, 2010 @ 2:01 AM PDT

I stumbled here looking for difference magic and very magic (\v) means in vim. Till today I could not figure out how to make vi deal with multi lines. But apparently this can be done using very magic flag.

My requirement was to insert a delimiter line say "_" as delimiter for every 4 lines.


Works perfectly in vim but still trying do decipher the nuances of magic vs very magic.