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.
This function takes into account the ikiwiki linking rules when deciding which file to go to.
> " NOTE: the root of the wiki is considered the first directory that contains a
> " .ikiwiki folder, except $HOME/.ikiwiki (the usual ikiwiki libdir)
>
> That's not going to work in all situations; for example, with an ikiwiki which uses git as the backend, the normal setup is that one has
>
> * a bare git repository
> * a git repository which ikiwiki builds the wiki from (which has a .ikiwiki directory in it)
> * an *additional* git repository cloned from the bare repository, which is used for making changes from the command-line rather than the web. It is this repository in which one would be editing files with vim, and *this* repository does not have a .ikiwiki directory in it. It does have a .git directory in the root, however, so I suppose you could use that as a method of detection of a root directory, but of course that would only work for git repositories.
>
> -- [[KathrynAndersen]]
>
>> You are completely right; all of my wikis are compiled both locally and
>> remotely, and so the local repo also has a `.ikiwiki` folder. And that's not the
>> "usual" setup.
>>
>> checking for a `.git` dir would not work when the wiki's source files aren't
>> located at the root of the repo.
>>
>> So, besides of doing a `touch .ikiwiki` at the root of the wiki in your local
well. I've rewritten the whole thing, to take into account:
* file matching ignoring case (MyPage matches mypage.mdwn)
* checking all the way down (up) to the root of the wiki (if there is a link `\[[foo]]` on `a/b/page`),
try `a/b/page/foo`, then `a/b/foo`, and so on, up to `foo`
* the alternate name for a page: when looking for the file for `\[[foo]]`, try both `foo.mdwn` and `foo/index.mdwn`
you can find the file [here](http://git.devnull.li/cgi-bin/gitweb.cgi?p=vim-jerojasro.git;a=blob;f=.vim/ftplugin/ikiwiki_nav.vim;hb=HEAD). To use it, place it in `$HOME/.vim/ftplugin`. After that, hitting `<CR>` (Enter) in normal mode over a wikilink will take you to that page, if it exists.
the plugin has, as of now, two problems:
* doesn't work with wikilinks that take more than one line (though this isn't really that bad)
* it assumes that the root of the wiki is the first directory down the filesystem hierarchy that
has a `.ikiwiki` folder on it. If your copy of the wiki doesn't have it, you must create it for
> Interesting. I was at one point looking at "potwiki.vim", which implements a local wiki and follows CamelCase links, creating new files where necessary etc., to see if it could be adapted for ikiwiki (See [[tips/vim syntax highlighting/discussion]]). I didn't get anywhere. -- [[Jon]]
2010-02-01 15:32:21 +01:00
>> when I wrote the plugin I also considered the possibility of creating files (and their dirs, if necessary)
>> from new wikilinks; the changes needed to get that working are fairly small -- [[jerojasro]]