Replies: 13 comments
-
I agree that this could be a very interesting feature to have. As well as generating a new link after picking a note, which might be more convenient than basic auto-completion. Most of the pieces are there, it would be a matter of sticking them together:
The last step might need some extra capabilities in |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in the next 5 days. |
Beta Was this translation helpful? Give feedback.
-
not stale, would still love to have this feature! |
Beta Was this translation helpful? Give feedback.
-
I'd like this same feature, except I don't think the picker should start with "a topic" prefilled, as it's easy to insert a link right now with its current title. Seems like you'd want to use this more in cases where the text you're highlighting is a bit different from the note title you're looking for. |
Beta Was this translation helpful? Give feedback.
-
Hey @nathanbraun what do you mean by "it's easy to insert a link right now"? Is there a command for that? |
Beta Was this translation helpful? Give feedback.
-
I have [[ mapped to open up the file picker, where I can pick a note. When I do a link is inserted with the note title as text. See code below for this. Note: what I (and @j-hui) would like is this same functionality, but where I can highlight some text, press [[ and have it open up the picker and insert a link where the text of the link is what was visually selected. Code for mapping [[ in insert mode to link picker. In my config, which is in lua: local opts = { noremap = true, silent = true}
local keymap = vim.api.nvim_buf_set_keymap
local zk = require("zk")
local commands = require("zk.commands")
local function yankName(options, picker_options)
zk.pick_notes(options, picker_options, function(notes)
local pos = vim.api.nvim_win_get_cursor(0)[2]
local line = vim.api.nvim_get_current_line()
if picker_options.multi_select == false then
notes = { notes }
end
for _, note in ipairs(notes) do
local nline = line:sub(0, pos) .. "[" .. note.title .. "]" .. "(" .. note.path:sub(1,-6) .. ")" .. line:sub(pos + 1)
vim.api.nvim_set_current_line(nline)
end
end)
end
commands.add("ZkYankName", function(options) yankName(options, { title = "Zk Yank" }) end)
keymap(0, "i", "[[", "<Cmd>ZkYankName<CR>", opts) |
Beta Was this translation helpful? Give feedback.
-
Oh amazing, thanks @nathanbraun that's a great addition. One tiny issue, do you have that when the file picker is opened ( |
Beta Was this translation helpful? Give feedback.
-
I use telescope and haven't run across that issue. Maybe try that? It's really quite good; no complaints at all. |
Beta Was this translation helpful? Give feedback.
-
Ah great, maybe I'll try that then. Have you also experienced an issue whereby the link that gets inserted from the above code is the wrong link? The title is always right but sometimes the link is for a different note. Seems to happen intermittently and I can't work out why |
Beta Was this translation helpful? Give feedback.
-
No but if I had to guess I bet it's something related to link structure, I'm doing it pretty manually, i.e. in this line:
Probably wouldn't work for notes that aren't 4 character strings (e.g. all my notes are like fvmg.wiki or tzvs.wiki etc). I'm sure there's some way to make it more flexible. Edit: I just tested this with some differently named notes, and it seems to work OK, so not sure what'd cause it, but I still bet it's something related to that -- maybe different file extensions? |
Beta Was this translation helpful? Give feedback.
-
Ah of course, silly me. My files are named |
Beta Was this translation helpful? Give feedback.
-
I went back and played with this some more. I was able to come up with some code that does what I wanted, e.g. let's you highlight some text and press
It's not perfect (i.e. throws an error on a multi line selection) but works well enough for me for now. |
Beta Was this translation helpful? Give feedback.
-
For future reference, this is now possible by |
Beta Was this translation helpful? Give feedback.
-
I am looking for some way to have the following workflow:
First, I type some text:
I realize I have a note for "a topic" that I would like to link to, title "the topic". I visual-select it:
I would like a command like
ZkLinkFromSelection
where it opens a picker pre-populated with "a topic". I adjust the query to search for just "topic". When I select the entry titled "the topic", it replaces the buffer text with a link:This is almost the same as
ZkNewFromTitleSelection
, except I don't want to create a new note, I want to link to an existing note.The current workaround is to delete "a topic", type "[[the topic", use completion to produce the link "[[the-topic-link|the topic]]", then replace "the topic" with "a topic". It's a bit cumbersome.
What would it take to implement this feature?
Beta Was this translation helpful? Give feedback.
All reactions