4

One of my favorite features of vimwiki is the way it handles links. Unfortunately, I use something else (vimoutliner) for my main note-taking, and it doesn't have anywhere near the linking capability that vimwiki does.

Is there a plugin that adds the linking functionality of vimwiki (or at least something similar) when editing any arbitrary file, and not just a *.wiki file?

Chris
  • 291
  • 5
  • 14

1 Answers1

7

I think you could just write one for your simple use case, something like:

function! LinkForward()
    let g:fromFile=expand('%:p')
    let fn= substitute(getline('.'),'^.*\[\[\([^\]]*\)\].*$',"\\1",'g')
    execute "e ".fn
endfunction

nnoremap <cr> :call LinkForward()<cr>

function! LinkBackward()
    execute "e ".g:fromFile
endf

nnoremap <bs> :call LinkBackward()<cr>

source this will do some similiar action, e.g pressing Enter on [[path/to/file/foo]]foo will go to that foo file, and within that file pressing <Backspace> will get you back.

note the codes above are just example, it won't work perfect. You could make it work better, e.g:

  • add a list/(stack) to store the file jump history.
  • define that this kind of action works only for certain filetype
  • check if the line under cursor doesn't match [[...]] then do normal <Enter>
  • etc.. if you like you could take a look vimwiki's codes and "borrow" some snippets for your personal usage.

hope it helps you.. & good luck.

Kent
  • 189,393
  • 32
  • 233
  • 301