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:

  1. User selects text in visual mode
  2. User runs command (e.g., :ZkNewFromTitle)
  3. User selects a template
  4. A new note is created with the selected text
  5. 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