4

Sometimes I want to autocomplete a tag name containing a colon, for example g:netrw_gx.

I've added to the 'tags' option the location of the tags file of the main documentation (which on my machine seems to be /usr/share/vim/vim74/doc/tags):

set tags+=$VIMRUNTIME/doc/tags

The default mapping to autocomplete a tag name is <C-x><C-]>.

The problem is if I type g:net and then hit <C-x><C-]>, Vim decides that the tag name begins after the colon, so the candidates which are suggested in the pop-up menu all begin with net, while I want candidates beginning with g:net.

I think the reason for this is given in an excerpt from :h ctrl-x_ctrl-]:

            Alphabetic characters and characters in 'iskeyword' are used
            to decide which characters are included in the tag
            name (same as for a keyword).

When looking for the tag name to complete, Vim takes probably all the characters from the cursor position back to the first character which is not in the 'iskeyword' option.
And a colon is not in 'isk', as the output of :echo &isk is @,48-57,_,192-255,# which doesn't contain : or 58 (ascii code of :).

I don't want to change the value of 'isk' as I suspect it would break many things (text-objects, plugins).

How can I autocomplete tag names containing a colon?

2

I understand that you prefer to avoid changing 'isk' permanently, but what about changing it during the autocompletion?

function! CustomComplTag()
   setlocal isk+=:
   call feedkeys("\<c-x>\<c-]>", "n")
endfunction
augroup CustomComplTagAutcmd
   au!
   autocmd CompleteDone * setlocal isk-=:
augroup END

inoremap <C-x><C-]> <C-o>:call CustomComplTag()<CR>

You could also check the plugins that use "CompleteHelper : Generic functions to support custom insert mode completions", maybe one of them does what you want, or is close enough so you can write a patch.

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.