michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

make link paths relative to current file #142

Closed rfhlmn closed 6 months ago

rfhlmn commented 7 months ago

When editing file a/b/c.md and trying to link to a/f/d.md, the current behaviour is to link from the root of the wiki, which doesn't work. I.e. the link would be 'a/f/d.md', when we need '../f/d.md'.

So here we make the link relative to the file we're editing.


I didn't find a place to write some unit tests, but it worked for the obvious three cases:

Do let me know if I should polish something up.

Happy holidays

rfhlmn commented 7 months ago

This should solve https://github.com/michal-h21/vim-zettel/pull/142

michal-h21 commented 7 months ago

Thanks, for this, this looks great! I will be mostly offline for the next 7 days, so I will test it and hopefully merge sometime in the next week, probably.

rfhlmn commented 7 months ago

I just realized this will probably break on Windows, as the path separator is "wrong" for Windows. I'll look into what I have to do to make that work as well. I can't test it, though, as I don't have a Windows machine.

michal-h21 commented 6 months ago

Sorry for the late reply, I've got some cold on my vacations.

I think forward slashes are not a problem on Windows, they should work in recent Windows versions. It would be also a problem if user shared the wiki over multiple machines with different operating systems.

rfhlmn commented 6 months ago

No worries, I hope you're all better now. :)

Oh, I didn't know that. Fair enough, that makes the code a bit easier as well.

Thank you!

michal-h21 commented 6 months ago

Yeah, I am OK now, thanks. I've set the s:path_sep variable to forward slash, but kept your original code in comments, so if we find in the future that backslashes are needed, we can use it.

rfhlmn commented 6 months ago

Glad to hear it!

Alright, cool, makes a lot of sense to me. :grin: