Reputation: 60058
I'd like to have vim (after pressing Ctrl+]) look up tags containing special characters like $
or @
. I can do it with the :tag
command (e.g., tag $some$symbol
) but it doesn't work with Ctrl+]
.
How can I configure what vim treats as an identifier?
Upvotes: 0
Views: 226
Reputation: 172540
Looking at :help CTRL-]
, it says:
CTRL-] Jump to the definition of the keyword under the cursor. Same as ":tag {name}", where {name} is the keyword under or after cursor.
From there, one might find :help 'iskeyword'
, or end up with :help word
, which explains:
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, ). This can be changed with the 'iskeyword' option. An empty line is also considered to be a word.
Therefore, you need to add $
to the 'iskeyword'
option:
:setlocal iskeyword+=$
The 'iskeyword'
option is local to buffer, and many syntax scripts rely on correct settings for highlighting. Therefore, it's not recommended to change this globally for all filetypes (with :set
, in your ~/.vimrc
).
Instead, you should identify the (few) filetype(s) were you need this, and then define this only locally.
Put the corresponding :setlocal
command into ~/.vim/after/ftplugin/{filetype}.vim
, where {filetype}
is the actual filetype (e.g. java
). (This requires that you have :filetype plugin on
; use of the after directory allows you to override any default filetype settings done by $VIMRUNTIME/ftplugin/{filetype}.vim
.)
Alternatively, you could define an :autocmd FileType {filetype} setlocal iskeyword+=$
directly in your ~/.vimrc
, but this tends to become unwieldy once you have many customizations.
Upvotes: 5