Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expressions in Vim

Tags:

regex

vim

I have been using Vim for a while now, and I've come to realize how powerful it is each time I do so. One thing that I know is that each usage leads me to a whole new learning experience about new commands that always seem to come in handy once I know them.

One thing I notice coming to SO is that a lot of users answer Vim questions in regexps. Things like this: :s/\(\S\+\)/"\1"/ (supposedly this is an awesome regexp). So I have two questions regarding this.

  • (a) Am I not harnessing the full power of Vim if I don't use regexps? Aren't there commands to do pretty much what any regexp would do?

  • (b) If you do think regexps are worth learning, please point me to reading material ranging from intro to advanced levels. If it helps, I use Vim mostly for writing up TeX files and Python scripts.

Thanks SO community, you rock.

like image 219
eqb Avatar asked Oct 13 '11 03:10

eqb


1 Answers

a) In my opinion, if you're not using it and you're happy the way you're working now, leave it at that. Once the time comes and you start needing regular expressions for something you'll learn them. To the extent you need. Most people use them in just that way.

Very few know them to the point where they, let's say go writing their own syntax files or something similar.

b) Vim has its own particular flavour of regular expressions (one of many), but for a start, apart from Vim's help of course, I'd recommend one of the introductory books to Perl. For example, Learning Perl. It has a nice gentle approach so that expressions start making sense (and you don't just learn them as one liners for some particular problem at hand). Beginning Perl (free version !) can be found here.

Advanced books on Regexes are Mastering Regular Expressions, and similar of the series. Also, Intermediate and Mastering Perl are not bad.

like image 73
Rook Avatar answered Nov 02 '22 19:11

Rook