--- Max Dyckhoff <[EMAIL PROTECTED]> wrote:
> > --- David Thompson [mailto:[EMAIL PROTECTED] wrote:
> > Does vim support a special type of 'iskeyword' setting for
> > Ctrl-] searching for tags?
> >
> > Here is my problem: after adding filenames to my tags file,
> > I now want to use the convenience of Ctrl-] to jump to files
> > as well as identifiers.
> >
> > For example, positioning the cursor on defines.h and pressing
> > Ctrl-], from inside a line like this,
> >
> >   #include "defines.h"
> >
> > I get an error,
> >
> >   E426: tag not found: defines
> >
> > But Ctrl-] finds the tag if I do this,
> >
> >   set iskeyword+=.
> >
> > I presume Ctrl-] is searching for the keyword under the cursor,
> > so the .h portion is not seen unless I add . to iskeyword.
> >
> > But adding . to iskeyword makes Ctrl-] work incorrectly on
> > identifiers in other cases, such as,
> >
> >   bufmgr.refcnt
> >
> > using Ctrl-] on bufmgr causes vim to search for bufmgr.refcnt,
> > which is obviously not correct.
> >
> > How do I solve this apparent discrepancy?
> >
> > Regards,
> >
> > David
>
> You could just use 'gf' to open the file under the cursor, assuming that it 
> lies in
> your path. ^wgf will open it in a new split, just like ^w^] does for tags.
> 
> If that isn't an acceptable solution, I don't have any other suggestions.

Well, I did solve the problem with a rather ugly function
that sets & resets iskeyword for one tag lookup.

But I was hoping vim might have a better way to use iskeyword
in a contextual manner specific just for tags.

Here is my solution:

I still use normal Ctrl-] for identifiers, but now use Ctrl-\
to tag on a filename.  It works pretty well, especially since
the ] and \ keys are next to each other on my QWERTY keyboard.

In my ~/.vimrc, I added,

  " map Ctrl-\ to do Ctrl-] on filenames
  nnoremap <silent> <C-\> :call TagFilename()<CR>
  function! TagFilename()
    let old_iskeyword = &iskeyword
    setlocal iskeyword+=\.,/
    let fname = expand('<cword>')
    let &l:iskeyword = old_iskeyword
    let v:errmsg = ""
    silent! execute ":tag ".fname
    if v:errmsg != ""
      echohl ErrorMsg
      echo v:errmsg
      echohl None
    endif
  endfunc

Regards,

David

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to