Skip to content

Instantly share code, notes, and snippets.

@andlrc
Created May 6, 2023 17:25
Show Gist options
  • Select an option

  • Save andlrc/29ce27f609dd3a55b47f63e7f460bde7 to your computer and use it in GitHub Desktop.

Select an option

Save andlrc/29ce27f609dd3a55b47f63e7f460bde7 to your computer and use it in GitHub Desktop.
" istagkeyword - add the content of the variable "b:istagkeyword",
" the content of the variable "g:istagkeyword",
" or a literal hyphen ('-'), in that order,
" to the 'iskeyword' option when jumping to tags
" Maintainer: Andreas Louv <andreas@louv.dk>
" Date: 2 Sep 2015
nnoremap <silent> <expr> <C-]> <Sid>Tag(':tag', "<C-]>")
nnoremap <silent> <expr> g<C-]> <Sid>Tag(':tjump', "g<C-]>")
nnoremap <silent> <expr> g] <Sid>Tag(':tselect', "g]")
nnoremap <silent> <expr> <C-w><C-]> <Sid>Tag(':stag', "<C-w><C-]>")
nnoremap <silent> <expr> <C-w>g<C-]> <Sid>Tag(':stjump', "<C-w>g<C-]>")
nnoremap <silent> <expr> <C-w>g] <Sid>Tag(':stselect', "<C-w>g]")
nnoremap <silent> <expr> <C-w>} <Sid>Tag(':ptag', "<C-w>}")
nnoremap <silent> <expr> <C-w>g} <Sid>Tag(':ptjump', "<C-w>g}")
cnoremap <expr> <C-r><C-w> <Sid>CtrlRCtrlW()
function s:GetTag() abort
let istagkeyword = get(b:, 'istagkeyword', get(g:, 'istagkeyword', '-'))
let save_isk = &l:iskeyword
if istagkeyword != ''
let &l:iskeyword = &l:iskeyword . ',' . istagkeyword
endif
let tag = expand('<cword>')
let &l:iskeyword = save_isk
return tag
endfunction
" get <C-r><C-w> to respect istagkeyword when needing tags
function! s:CtrlRCtrlW() abort
if getcmdtype() == ':'
if getcmdline() =~ '^\(\d*[sp]\=t\%[ag]\|[sp]\=ts\%[elect]\|[sp]\=tj\%[ump]\|lt\%[ag]\)!\=\s\+$'
return s:GetTag()
endif
endif
return "\<C-r>\<C-w>"
endfunction
function! s:Tag(cmd, origcmd) abort
" help files sanitize the tag in in odd ways, before jumping to it
" see the function "find_help_tags" in the vim source code for details
if &ft == 'help'
return a:origcmd
endif
let tag = s:GetTag()
return a:cmd . ' ' . tag . "\<Cr>"
endfunction
@Konfekt
Copy link

Konfekt commented Sep 15, 2025

Thank you. Surely you have an example where this proved useful? Maybe applicable here or there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment