3

As title says, I try to select the whole word with viw but if the naming convention is aaa-b-ccc, then I can't do that with this command. I have tried viW but this will include other symbols too which is not what I want.

Is there a way to only include - for w?

2

1 Answer 1

7

You can control that with the 'iskeyword' option. To include dashes, you can use this command:

set iskeyword+=-

You'll probably want to use setlocal and limit that to the specific filetype where you want dashes to be recognized as identifiers.

You can create a file ~/.vim/after/ftplugin/<your-filetype>.vim with that setlocal command to ensure - is always included in words when editing files of that specific type.

See also :help 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.

3
  • 1
    Just tried this out and work perfectly! Thanks a lot for this great answer! :)
    – Tony Lin
    May 26, 2020 at 4:35
  • 1
    @TonyLin Glad it worked for you!
    – filbranden
    May 26, 2020 at 4:35
  • 3
    @TonyLin just remember this affects all word motions (which you probably wanted)!
    – D. Ben Knoble
    May 26, 2020 at 13:32

Your Answer

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

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