5

expand(<cword>) gives me the word under the cursor, but it excludes symbols such as @ or .. For example, if I call it at the end of @word, it will get me word and exclude the @.

Is there a way that I could include symbols as part of the current word?

8

The characters that are included in a Vim word are set by the 'iskeyword' option. See

:help <word>
:help word
:help 'iskeyword'

To add another character to this set, such as ., execute the following:

:set iskeyword+=.

See

:help :set+=

Note that the character @ is special, so it has be added like this:

:set iskeyword+=@-@

See

:help 'isfname'
  • 1
    @-@? Is that Bram's way of showing he's mad at use for making @ part of words? – muru Jul 22 '15 at 5:59
  • 1
    Note that there are side effects to changing iskeyword. For example, if you add @ to iskeyword, the standard word motion command (w) will also move across e.g. @word @otherword. – Karl Yngve Lervåg Jul 22 '15 at 14:13
4

Use expand(<cWORD>).

From :help :<cWORD>:

<cWORD> is replaced with the WORD under the cursor (see WORD)

and from :help WORD:

A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.

A sequence of folded lines is counted for one word of a single character. "w" and "W", "e" and "E" move to the start/end of the first word or WORD after a range of folded lines. "b" and "B" move to the start of the first word or WORD before the fold.

  • Thanks, @Carpetsmoker! I didn't have the time to expand my answer until now. – Karl Yngve Lervåg Jul 22 '15 at 14:04

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.