4

I see a lot of members here manipulating and using regexp very easily. I am slowly learning, one trick at a time, how to search for this or that, how to handle this case, how to escape that case... But at this rate, it will take me ages before I can efficiently use VIM's regexp. I also tried to read the documentation, but all the small symbols/special characters are not the easiest to remember.

I am therefore asking if there is any kind of "regexp" tutorial you came across during your learning process.

I found vimregex.com that's already a very good start, but maybe some of you have even better / more interactive / easier answers ?

Edit This question was put "on hold" for being "primarily opinion-based", which I understand. The few answers and comments I got however gave a few interesting tips, so I changed my question to the current one. I guess it's still opinion-based ? But maybe more useful this way ?

closed as primarily opinion-based by nobe4, vappolinario, Sundeep, DJMcMayhem, SibiCoder Jun 24 '16 at 18:59

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    I learned POSIX regex from this book and just picked up Viim's syntax over time. (Still learning some of the more complicated vim stuff like \zs) – Tumbler41 Jun 24 '16 at 14:35
  • 2
    You should post your question on reddit.com/r/vim. – nobe4 Jun 24 '16 at 14:36
  • 1
    Sometimes, it's not just the regexp (I think you learn it when you need it), but also regex and global/substitute/ex commands in combination. For this, I heartily recommend this tutorial (adapted to Vim): dahu.github.io/vim_waz_ere Regexp-wise, do learn Vim's specific matchers: \zs, \ze, they simplify substitution a lot. – VanLaser Jun 24 '16 at 14:37
  • 8
    Don't think that any answer with a regexp is made "very easily". I often have to muck about a bit and refer to the documentation! And I figure most people learned it the same way you're doing: "one trick at a time", and with quite a bit of effort... – Martin Tournoij Jun 24 '16 at 14:45
  • 2
    It ultimately boils down to your learning style, but I'd personally recommend against interactive regex mungers and the like. Rather, read the man page for mawk(1), it's one of the most well-written and to-the-point man pages. Focus on concepts, not syntax. When you're done you'll know awk(1), which is tremendously useful by itself, and you'll have an easy time understanding the differences in syntax between sed(1), grep(1), perl(1), vim(1) and so on. – lcd047 Jun 24 '16 at 15:44
3

Along with what everybody else said, I have a custom help file specifically for regex. Anytime I learn something that's useful, but might be hard to remember, I stick it in the help file. I can pull up this help file with a single keystroke and reference it whenever I need.

This way when you learn things it's not like trying you're trying to hold all your knowledge in a sieve. And as time goes on, you might be able to remove things from the help file because you've used them so much that you know them by heart. Ultimately it's a process that you're just going to have to go through, but this tool has helped me a LOT, so I thought I'd share it.

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