Add_mappings_to_ease_working_with_underscores

1 Point

Kazark Kazark

9 years ago

Do you ever work with code_that_has_lots_of_underscores, and sometimes you want to treat that whole thing as a word, and other times you want to only treat the individual parts between underscores as words? For example, if you are writing Python code, you might want to treat method calls like method_call as a single word, but if you are writing NUnit tests like My_function_should_behave_in_this_certain_way, then you might want to treat the underscores like spaces. Here is a simple solution that will give you movements analogous to your standard word movements and also give you motions so you can do things like c3u to change the text for three of the words between underscores or d3U to delete three of the words, along with their underscores. If you always want underscores to act like spaces, you can tell Vim to treat them as word-delimiters. If you want them to be in some scenarios but not others, the mappings below may be for you.

map <leader>w f_l
map <leader>b hT_
map <leader>e lt_
omap u t_
omap U f_