Is it possible to alias regexp substrings in vim?

1

I want to find and replace pattern containing floating point numbers using vim. I found this nice regular expression for such numbers:

 [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?

This expression makes any regex it appears in quite long and confusing. Also I would probably want to use it quite often.

Is there some way that vim can learn this substring as an alias so that I can just search for something like Value: +[[:float:]] instead of Value: +[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)??

Tim

Posted 2013-08-27T14:14:37.360

Reputation: 1 811

Answers

2

While I don't think what you want exists, abbreviations should help you, here.

cabbrev float [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?

Practically, you'll use it like this:

:
:s/
:s/float/
:s/[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/

romainl

Posted 2013-08-27T14:14:37.360

Reputation: 19 227

Thank you! This is perfect for repeatedly using a longer regexp. The only thing that is missing would be that the abbreviation is not resolved before adding the command to the history, but this seems not possible. Even without this it helps a lot! – Tim – 2013-08-27T15:24:42.717