vimwiki local file link handling

5.5k views Asked by At

I would like vimwiki to open .tex files in vim (in the same way it open wiki files in vim).

I'm running cygwin, and I finally succeeded in making vimwiki open links the way it "should" by replacing 'xdg-open ' with 'cygstart ' in the vim#wiki#base#system_open_link function, and so now pdfs open in a pdf viewer, urls open in a browser, etc, which is great. But when cygstart is applied to .tex files, it opens the windows copy of gvim in another window.

Is there any way of configuring vimwiki to not use cygstart when the local file has a .tex extension, but rather treat it exactly the same way it treats .wiki files?

1

There are 1 answers

0
user59959 On

I found the answer in the vimwiki help file. There is an example of the VimWikiLinkHandler function that opens vlocal files in vim. I just copied this function into plugin/vimwiki.vim:

function! VimwikiLinkHandler(link) "{{{ Use Vim to open links with the
  " 'vlocal:' or 'vfile:' schemes.  E.g.:
  "   1) [[vfile:///~/Code/PythonProject/abc123.py]], and
  "   2) [[vlocal:./|Wiki Home]]
  let link = a:link
  if link =~ "vlocal:" || link =~ "vfile:"
    let link = link[1:]
  else
    return 0
  endif
  let [idx, scheme, path, subdir, lnk, ext, url] =
       \ vimwiki#base#resolve_scheme(link, 0)
  if g:vimwiki_debug
    echom 'LinkHandler: idx='.idx.', scheme=[v]'.scheme.', path='.path.
         \ ', subdir='.subdir.', lnk='.lnk.', ext='.ext.', url='.url
  endif
  if url == ''
    echom 'Vimwiki Error: Unable to resolve link!'
    return 0
  else
    call vimwiki#base#edit_file('tabnew', url, [], 0)
    return 1
  endif
endfunction " }}}