I am starting to have issues with my pinky finger. I tend to write variables and functions using underscores as in my_variable. I would like to find a way to avoid having to press "shift + -" to get the underscore. One way I thought of is by having vim transform -- to _ automatically as I type. How can I do that? Other alternatives to writing _ are welcome.


2 Answers 2


Sorry about your pinky. :)

You could try one of...

:inoremap -- _


:iabbrev -- _

The difference has to do with when the substituted character appears. With mappings it's immediately. With abbreviations it's after you type a non-keyword character (e.g. Space).

Of course, if your primary use case is, as you suggested, snake_case variable names...and so the underscore is always followed by a keyword character...then the first one is the only practical choice! The alternative may be of interest to other folks, though.


A slightly more complicated solution that mirrors what I do for SHOUTY CAPS.

For upper case, I type in lower case and then use something like gUiw to change the case.

For - to _, I would use tpope's vim-abolish to type my-variable and then use cr_ (which only needs one _ typed) or crs (which needs none).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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