michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
557 stars 74 forks source link

auto-complete using [[ inserts | #4

Open elliottw opened 5 years ago

elliottw commented 5 years ago

so after typing [[ and getting FZF to pop up, I selected sarah.md and the resulting output was [[sarah.md|

michal-h21 commented 5 years ago

Thanks for the report. It includes link in the vimwiki format, which is [[filename|title. Because Markdown format doesn't have explicit title markup, you get the title empty. It doesn't insert the closing parenthesis because vimwiki hides links and you wouldn't be able to insert the title easily.

I've modified the autocomplete function to insert correct link according to the current markup. You will probably still need to insert a meaningful title explicitly.

elliottw commented 5 years ago

thanks! gets me a little closer.

abers commented 4 years ago

Unsure whether to open this as separate issue or not but when inserting markdown links via typing [[ it inserts the link in markdown syntax - but leaves boths [[ at the start and deletes everything 1-4 lines below.

michal-h21 commented 4 years ago

@abers oh, that is strange. I cannot reproduce it. You can see the code that inserts the link here: https://github.com/michal-h21/vim-zettel/blob/2313cf7ef4195892199218bc7ccd59e4944493bb/ftplugin/vimwiki.vim#L38

It deletes two characters that will be replaced with the new link ([[]) using xx, so maybe that deletes something more in your case?

abers commented 4 years ago

Apologies! Just realised that it was not deleting the lines. Instead, because there was no closing ) being added to the end of the inserted link conceal was then hiding everything between the link and the next ).

So when I type '[[', search for note and hit enter to accept it, it adds the note title and the link but keeps both [[ and doesn't add the ) at the end. For example, if I select a note titled "test" from 16th April 2019 I get -

[[test](190416-1229

- and placed back in normal mode. I don't know what others think, but It would be preferable for me to have -

[test](190416-1229)

- and remain in Insert mode.

michal-h21 commented 4 years ago

@abers The problem is that when the inserted link doesn't contain title, you would need to use insert mode commands to move back to the title and insert it manually. As soon as you switch to the normal mode to move back faster, the link will be hidden. So this is the reason why non-complete links are inserted. I am open to a better solutions of course.

abers commented 4 years ago

Is there a way to detect whether a link has a title? Similarly, is it possible through a vim plugin to add hotkeys to the fzf window that pops up?

If so, could have it so if the selected zettel has a title then insert full link and remain in insert mode. If no title then insert [ ](190416-1229), move cursor between the square brackets [ ], and enter insert mode. Finally, could have ctrl+enter when there's a title to insert the full link and return to normal mode. Could also add a binding for inserting link without title and enter insert between square brackets for situations where people want to link to a zettel but want the link text to be something else instead of the title.

michal-h21 commented 4 years ago

That is a good idea. I've modified the link insertion behaviour so the cursor is moved to the right place if the title is empty. It works both in Vimwiki and Markdown syntaxes. I've realized that there is currently no code for the title detection in Markdown. In contrast to Vimwiki, there is no clear title indicator in Markdown. We can probably use the first header in the linked file for this purpose.

abers commented 4 years ago

I don't know about others using Markdwon but I add a YAML block to the top of my zettels with key/value pairs for title, date, and tags. The YAML block title and date are already auto-populated by vim-zettel.

michal-h21 commented 4 years ago

Ah, you are right, I totally forgot that the functionality for title detection works even in Markdown, as I use only the Vimwiki syntax. It seems that the title insertion works when the linked page contains:

 title: title