zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
530 stars 42 forks source link

feat: pass a custom title to ZkInsertLink during execution #156

Closed tjex closed 10 months ago

tjex commented 10 months ago

Currently, when inserting a link with ZkInsertLink, a markdown link is returned with a blank title, and the cursor residing at the end of the inserted link.

eg:

Here, and inserted link: [](path)| <-- cursor

This requires the user to navigate backwards, which isn't so optimal and can break the flow of writing.

This PR therefore adds the option to pass a title via a table to the ZkInsertLink command (in keeping with the same syntax present throughout the API).

ZkInsertLink {title = "custom title"} will therefore result in, the picker opening, and after selection of a note:

Here, and inserted link: [custom title](path)| <-- cursor

I see this is a beneficial use case, and as an alternative to [[ completion because there are many times where we know we want to link to something, by using an alternate title.

eg:

[There are multiple reasons](/research/list-of-reasons.md) to accept this PR.

I wrote about that [yesterday](/diaries/...)

This also negates the need to first write a phrase, highlight that phrase and execute ZkInsertLinkAtSelection, which is of course still a good option, but it's an extra step if we already know what we want to write.

This would also of course enable such a keybind:

-- insert a link with custom title (or leave blank)
vim.keymap.set("n", "<leader>zl", ":ZkInsertLink {title = vim.fn.input('Link text: ')}<cr>")