2

I was wondering if there is a single key (like 'w') that specifies "from the current cursor position to the next non alphanumeric character".

This is the scenario: In the example below, with the cursor under 'e', I want to delete the 'example' word (between underscores):

this_example_word 

With the cursor under 'e', if I press dw, i delete example_word, not example. I know that I can do dt_, but I was wondering if Vim has a "word" concept that implies only a-zA-Z0-9, so that I can press dX o cX and delete/replace only example.

Best regards,

1 Answer 1

5

vim treats a sequences of [A-Za-z0-9_] or sequences of non-blank characters separated with white space as a word, sequences of non-blank characters separated with white space as a WORD. You can re-define what word mean to vim:

set iskeyword-=_

Now place your cursor at e, press d+w or d+e

4
  • Very interesting, I didn't know that underscore was the ONLY special character appart from :alpha: ... Thanks a lot for your answer, now works as expected.
    – sromero
    Jan 19, 2016 at 8:30
  • I found a problem with the above solution. Now Vim doesn't consider "in_array" a PHP keyword... so it also affects to syntax highlighting, not only to the "definition of word" for w, W, b and B ... any idea?
    – sromero
    Jan 19, 2016 at 10:31
  • @sromero: Maybe you should define a function to toggle adding/removing _ from iskeyword.
    – cuonglm
    Jan 19, 2016 at 10:45
  • 1
    @sromero: You can read this link for some ideals.
    – cuonglm
    Jan 19, 2016 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .