michal-h21 / vim-zettel

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

Automatic backlinks on save #56

Open guilhermeprokisch opened 3 years ago

guilhermeprokisch commented 3 years ago

It's is possible to automatically run the ZettelBackLinks on the file save?

michal-h21 commented 3 years ago

It could be probably done using the BufWritePost auto action provided by Vim. There are two problems: not all pages need to have backlinks (at least the index page, tag index, etc.), so you need to check if the current page contains backlinks first.

Second issue is more serious - at least for me, each time I run :ZettelBacklinks, it doesn't update the existing links, but it adds them above the existing links, so you would get lot of duplicates quickly. This issue needs to be fixed first.

But I like this idea and I will hopefully come with the solution.

Vamsee30 commented 3 years ago

It could be probably done using the BufWritePost auto action provided by Vim. There are two problems: not all pages need to have backlinks (at least the index page, tag index, etc.), so you need to check if the current page contains backlinks first.

Second issue is more serious - at least for me, each time I run :ZettelBacklinks, it doesn't update the existing links, but it adds them above the existing links, so you would get lot of duplicates quickly. This issue needs to be fixed first.

But I like this idea and I will hopefully come with the solution.

I have no idea how to code this, but what if the :ZettelBacklinks & ZettelInbox inserted those links contained within some kind of tag like [BL][/BL], so that when it is updated, it can easily be replaced with regular expressions or something?

folofjc commented 3 years ago

Second issue is more serious - at least for me, each time I run :ZettelBacklinks, it doesn't update the existing links, but it adds them above the existing links, so you would get lot of duplicates quickly. This issue needs to be fixed first.

I have this issue as well. Is this being tracked in a separate issue?