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]+)??

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]+)?/
  • 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 Aug 27 '13 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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