{"id":4870,"date":"2021-07-15T22:25:35","date_gmt":"2021-07-16T01:25:35","guid":{"rendered":"https:\/\/bureau-it.com\/artigos\/how-to-enable-extended-regex-in-vim\/"},"modified":"2024-09-19T22:33:48","modified_gmt":"2024-09-20T01:33:48","slug":"how-to-enable-extended-regex-in-vim","status":"publish","type":"post","link":"https:\/\/bureau-it.com\/en\/artigos\/how-to-enable-extended-regex-in-vim\/","title":{"rendered":"How to enable Extended REGEX in VIM"},"content":{"rendered":"\n

<\/span>Estimated reading time: <\/span>5<\/span> minutes<\/span><\/p>\n\n

Introduction<\/h2>\n\n

In general, there are far less insane ways of creating regular expressions than within VIM<\/a>.\nThat’s why you might want to use other tools to test, validate and then import your regex into the text editor. <\/p>\n\n

Save time with a good tester<\/h2>\n\n

An interesting regex tester is regex101.com<\/a>, which helps a lot when composing a huge expression.\nThere are other very nice ones, but this is my favorite. <\/p>\n\n

Once you’ve come up with the perfect expression, you discover in VIM that you now have to escape characters that shouldn’t be literal!\nAnd then you have to turn them into specials to make it all work… <\/p>\n\n

But there is a great solution, which consists of calling an internal option called very magic<\/em>, which will help a lot to avoid escaping lots of ( { } ) <\/code>in long regular expressions. <\/p>\n\n

Very Magic!<\/h2>\n\n

So, to use very magic, just insert an additional command before the regular expression: \\v<\/code><\/p>\n\n

In a simple and uncreative example \ud83d\ude06, we match group 1 (Magia) <\/code>and then bring it back with \\1<\/code>, adding very magic<\/code>, ignoring anything else that is not matched in this expression.<\/p>\n\n

#sem very magic\n:%s\/\\v\\(Magia\\) furta-cor\/\\1 very magic\/g\n\n#com very magic\n:%s\/\\v(Magia) furta-cor\/\\1 very magic\/g<\/pre>\n\n