Regular Expressions in Vim

I have been using Vim for a while, and I realized how effective it is every time I do it. The only thing I know is that every use leads me to a new new experience regarding new teams that always seem useful to you when I know them.

One thing I notice is that many users answer Vim's questions in regular expressions. Things like this :s/\(\S\+\)/"\1"/ (presumably this is a terrific regular expression). Therefore, I have two questions.

  • (a) Don't I use the full power of Vim if I don't use regular expressions? Are there any teams that could do something that any regex could do?

  • (b) If you think that regular expressions are worth exploring, give me reading material, from input to advanced levels. If this helps, I use Vim mainly for writing TeX files and Python scripts.

Thank you community, you swing.

+4
source share
2 answers

a) In my opinion, if you are not using it and you are happy with the way you are working now, leave it to that. As soon as the time comes, and you begin to need regular expressions for something, you will recognize them. As far as you need. Most people use them that way.

Very few know them to such an extent that they, let them say, have written their own syntax files or something like that.

b) Vim has its own special flavor of regular expressions ( one of many ), but for starters, besides Vim's help, of course, I would recommend one of the introductory books for Perl. For example, Learning Perl . It has a nice, gentle approach, so expressions begin to make sense (and you don't just study them as one liner for some specific problems). Starting with Perl (free version!) Can be found here .

Extended Books on Regexes Mastering Regular Expressions and Similar Series. In addition, intermediate and mastering Perl are not bad.

+9
source

Essentially regular expressions are most useful for searching and replacing. Many problems can be resolved by searching for offensive text and replacing it in a smart way with the desired text. This is not always the best way to solve, and rarely is the only way. Regular expressions find a pattern, so if you want to edit text in a bunch of places that have a similar pattern, you can often identify them with a regular expression Example:

 /my name is .* 

Find "my name" "My name is Joe" or anything else that starts with "my name"
. matches any character, and * indicates vim matching 0 at infinity of the previous character (in this case . or something else)
this is probably the simplest form of regular expression. for more advanced use, use the answers provided by Idigas

+2
source

All Articles