1 I wrote a vim function to help me navigate the wiki when I'm editing it. It extends the 'gf' (goto file) functionality. Once installed, you place the cursor on a wiki page name and press 'gf' (without the quotes); if the file exists, it gets loaded.
3 This function takes into account the ikiwiki linking rules when deciding which file to go to.
5 let me know what you think
7 To enable this functionality, paste the code below in your `.vim/ftplugin/ikiwiki.vim` file
9 " returns the directory which can be considered the root of the wiki the
10 " current buffer belongs to, or an empty string if we are not inside an
13 " NOTE: the root of the wiki is considered the first directory that contains a
14 " .ikiwiki folder, except $HOME/.ikiwiki (the usual ikiwiki libdir)
16 " if you can think of a better heuristic to get ikiwiki's root, let me know!
17 function! GetWikiRootDir()
18 let check_str = '%:p:h'
19 let pos_wiki_root = expand(check_str)
20 while pos_wiki_root != '/'
21 if isdirectory(pos_wiki_root . '/.ikiwiki') && pos_wiki_root != $HOME
24 let check_str = check_str . ':h'
25 let pos_wiki_root = expand(check_str)
27 if isdirectory('/.ikiwiki')
33 " This function searches for a .mdwn file (<a:name>.mdwn) using the ikiwiki
34 " WikiLink rules and returns its full path.
36 " The rules are the following
38 " if the filename starts with '/', use as base dir the root directory of the
43 " try first ./<bufname>/<a:name>.mdwn
44 " then for ./<a:name>.mdwn
45 " then for <root_of_wiki>/<a:name>.mdwn
47 " return the first one that exists
49 " the base path (. above) is the directory that contains the current buffer
51 function! FileForWikiLink(name)
52 let target_fname=a:name . ".mdwn"
53 let wikiroot_dir = GetWikiRootDir()
54 if match(target_fname, '^/') >= 0
55 return wikiroot_dir . target_fname
57 let subdir_file = expand('%:p:r') . "/" . target_fname
58 let currdir_file = expand('%:p:h') . "/" . target_fname
59 let wikiroot_file = wikiroot_dir . "/" . target_fname
60 if filewritable(subdir_file)
63 if filewritable(currdir_file)
66 if filewritable(wikiroot_file)
72 setlocal includeexpr=FileForWikiLink(v:fname)