user3591723
user3591723

Reputation: 1284

Vim tags with filenames containing a $

When I have a ctags entry that is in a filename containing a $ such as foo/bar/File$With$Dollars.ext vim won't open that file but will instead try to open foo/bar/Baz.ext. I tried making the output tag filename escape the $ with \$ - as you would do when opening that file with :e foo/bar/File\$With\$Dollars.ext - but that didn't work either.

Concretely, let's say I've got the following tag:

fooFunction     foo/bar/File$With$Dollars.ext   23;"    f

How can I make vim understand the $ is part of the file name when that file name is supplied by a ctags tags file?

Upvotes: 2

Views: 80

Answers (1)

user3591723
user3591723

Reputation: 1284

I'm not particularly good with vimscript, but I ended up doing this:

function SmaliFileFixTagFileName()
    let fname = expand("<afile>")
    let delbuf = 0
    if (stridx(fname, "$") != -1 )
        if (stridx(fname, "\\$") == -1)
            let fname = escape(fname, "$")
        else
            let delbuf = 1
        endif
    endif
    exe "silent doau BufReadPre " . fname | exe "edit " . fname | exe "silent doau BufReadPost " . fname
    if (delbuf == 1)
        exe "bd " . escape(escape(fname, "\\"), "$")
    endif
endfunction

augroup tagfix
    au!
    au BufReadCmd *.smali call SmaliFileFixTagFileName()
augroup end

and ensuring the tags were generated with filenames escaping the $ as \$.

It works for what I need. I'll leave this open for a bit just in case anyone has a better solution.

Upvotes: 1

Related Questions