15

Is it possible for vim to treat underscores like spaces or hypens, so when I use the sequence dw, it doesn't delete whole sentence some_long_text_with_underscores, when the cursor is at the beginning?

22

dw deletes a word, and what constitutes a word is defined by the iskeyword setting. From :h word:

                                                        word
A word consists of a sequence of letters, digits and underscores, or a
sequence of other non-blank characters, separated with white space (spaces,
tabs, <EOL>).  This can be changed with the 'iskeyword' option.  An empty line
is also considered to be a word.

To remove _ from iskeyword, do:

set iskeyword-=_
  • 1
    It turned out to be a double-edged sword, as vim started to treat long function names as separate words. For example, a python function called ,,download_and_print()" is going to have colored ,,and'' - as this is a language keyword. It's also impossible to navigate with */# between function calls. I know it wasn't the part of the question, but wanted to mention this. – jligeza Oct 6 '15 at 7:54
  • @zmarszczony my function highlighting works fine, but */# is gone. – muru Oct 6 '15 at 9:05

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.