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 > 'gf' gets in the way when there are directories with the same name of a wiki page. The
6 > function below doesn't implement the linking rules properly (test the link (ignoring case),
7 > if there is no match ascend the dir. hierarchy and start over, until we reach the root of
8 > the wiki). I'm rewriting it to follow these rules properly
10 > I think the page for [[LinkingRules|ikiwiki/subpage/linkingrules]] should say that ikiwiki **ascends**
11 > the dir. hierarchy when looking for a wikilink, not that it **descends** it. Am I correct? --[[jerojasro]]
13 >> Conventionally, the root directory is considered to be lower than other
14 >> directories, so I think the current wording is correct. --[[Joey]]
16 let me know what you think
18 > " NOTE: the root of the wiki is considered the first directory that contains a
19 > " .ikiwiki folder, except $HOME/.ikiwiki (the usual ikiwiki libdir)
21 > 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
23 > * a bare git repository
24 > * a git repository which ikiwiki builds the wiki from (which has a .ikiwiki directory in it)
25 > * 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.
27 > -- [[KathrynAndersen]]
29 >> You are completely right; all of my wikis are compiled both locally and
30 >> remotely, and so the local repo also has a `.ikiwiki` folder. And that's not the
33 >> checking for a `.git` dir would not work when the wiki's source files aren't
34 >> located at the root of the repo.
36 >> So, besides of doing a `touch .ikiwiki` at the root of the wiki in your local
37 >> repo, do you see any alternative?
41 well. I've rewritten the whole thing, to take into account:
43 * file matching ignoring case (MyPage matches mypage.mdwn)
44 * checking all the way down (up) to the root of the wiki (if there is a link `\[[foo]]` on `a/b/page`),
45 try `a/b/page/foo`, then `a/b/foo`, and so on, up to `foo`
46 * the alternate name for a page: when looking for the file for `\[[foo]]`, try both `foo.mdwn` and `foo/index.mdwn`
48 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.
50 the plugin has, as of now, two problems:
52 * doesn't work with wikilinks that take more than one line (though this isn't really that bad)
53 * it assumes that the root of the wiki is the first directory down the filesystem hierarchy that
54 has a `.ikiwiki` folder on it. If your copy of the wiki doesn't have it, you must create it for
59 > 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]]
61 >> when I wrote the plugin I also considered the possibility of creating files (and their dirs, if necessary)
62 >> from new wikilinks; the changes needed to get that working are fairly small -- [[jerojasro]]
64 > Seems about ready for me to think about pulling it into ikiwiki
65 > alongside [[tips/vim_syntax_highlighting/ikiwiki.vim]]. If you'll
66 > please slap a license on it. :) --[[Joey]]
68 > Also, I have a possible other approach for finding ikiwiki's root. One
69 > could consider that any subdirectory of an ikiwiki wiki is itself
70 > a standalone wiki, though probably one missing a toplevel index page.
71 > The relative wikilinks work such that this assumption makes sense;
72 > you can build any subdirectory with ikiwiki and probably get something
73 > reasonable with links that work, etc.
75 > So, if that's the case, then one could say that the directory that the
76 > user considers to be the toplevel of their wiki is really also a subwiki,
77 > enclosed in a succession of parents that go all the way down to the root
78 > directory (or alternatively, to the user's home directory). I think that
79 > logically makes some sense.
81 > And if that's the case, you can resolve an absolute link by looking for
82 > the page closest to the root that matches the link.
84 > It may even make sense to change ikiwiki's own handling of "absolute"
85 > links to work that way. But even without changing ikiwiki, I think it
86 > would be a reasonable thing for vim to do. It would only fail in two
87 > unusual circumstances:
89 > 1. There is a file further down, outside what the user considers
90 > the wiki, that matches. Say a `$HOME/index.mdwn`
91 > 2. An absolute link is broken in that the page linked to does
92 > not exist in the root of the wiki. But it does exist in a subdir,
93 > and vim would go to that file.