Replace visual selection with link when creating notes from templates
Description
Commands that create new notes from templates based on visual selections should replace the selected text with a link to the newly created note.
Affected Commands
The following commands create notes from visual selections with templates:
-
ZkNewFromTitle(lua/zk-extras/commands/new_selection_with_template.lua:92) -
ZkNewFromContent(lua/zk-extras/commands/new_selection_with_template.lua:96)
Current Behavior
When creating a note from a visual selection:
- User selects text in visual mode
- User runs command (e.g.,
:ZkNewFromTitle) - User selects a template
- A new note is created with the selected text
- The original selection remains unchanged in the source buffer
Expected Behavior
After creating the note, the visual selection should be automatically replaced with a markdown link to the newly created note:
[selected text](path/to/new/note.md)
or using the note ID if available:
[selected text](id:note-id)
Implementation Considerations
- The replacement should happen after the note is successfully created
- Need to access the created note's path/ID from zk-nvim's
zk.new()callback/response - Should handle both title-based and content-based note creation
- Consider user configuration option to enable/disable this behavior
- Maintain visual selection position for proper replacement
Benefits
- Streamlines workflow for creating linked notes from selections
- Reduces manual steps (creating note + manually adding link)
- Common pattern in zettelkasten workflows