Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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]+)?/
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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