Re: Using Ctrl-] to tag on a filename
Hi, On 10/17/06, David Thompson <[EMAIL PROTECTED]> wrote: --- 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. > > > > 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 :call TagFilename() function! TagFilename() let old_iskeyword = &iskeyword setlocal iskeyword+=\.,/ let fname = expand('') If you use expand(""), then you don't need to change the 'iskeyword' setting. For example, you can use the following map: nnoremap :tag expand(":t") - Yegappan let &l:iskeyword = old_iskeyword let v:errmsg = "" silent! execute ":tag ".fname if v:errmsg != "" echohl ErrorMsg echo v:errmsg echohl None endif endfunc
RE: Using Ctrl-] to tag on a filename
--- 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 :call TagFilename() function! TagFilename() let old_iskeyword = &iskeyword setlocal iskeyword+=\.,/ let fname = expand('') 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
RE: Using Ctrl-] to tag on a filename
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. Max > -Original Message- > From: David Thompson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, October 17, 2006 4:22 PM > To: vim@vim.org > Subject: Using Ctrl-] to tag on a filename > > 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 > > __ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com