michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

Use Visual Selection as Lable for Link to Existing Zettel #108

Closed tbsmn closed 2 years ago

tbsmn commented 3 years ago

Hi, I was wondering if there is a way to achieve the following. I would like to visualy select a word (or multiple words) in as visual selection and than triggering <plug>ZettelSearchMap resulting in Link to the Zettel I searched for but with the selected Text as lable (Markdownstyle links).

Example In the sencence "His mother called him Albert" I want to select "Albert" , trigger the command, searach my wiki/zettelkasten for to entry with the Title "Alber Einstein" and create a link. Normaly the lable of the link would be "Albert Einstein" [Albert Einstein](albert_einstein.md) but I want it to be selected text, in this case "Albert" [Albert](albert_einstein.md) .

Is there a way to achieve this? I tried this mapping

augroup filetype_vimwiki
    autocmd!    
    autocmd FileType vimwiki vmap <silent> zl y <esc><Plug>ZettelSearchMapF[vi[pf}a
augroup END

But this enters the Keysequence F[vi[pf}a as searchstring in the ZettelSearch

Any Idea how I could achieve this?

michal-h21 commented 2 years ago

Hi, sorry for the late reply. I've recently implemented this feature, the [[ mapping works in visual mode, and it will use the selected text as a title.

tbsmn commented 2 years ago

Thank You! That is awsome. Sadly I can't get it to work. If I select a text in visual mode and the press [[ I jump back to the last heading. This is my Zettel related part in my vimrc

let g:zettel_format = "%y%m%d-%H%M-%title"

let g:zettel_default_mappings = 0
augroup filetype_vimwiki
    autocmd!
    autocmd FileType vimwiki imap <silent> [[ ? <esc><Plug>ZettelSearchMap
    autocmd FileType vimwiki nnoremap zn :ZettelNew<space>
    autocmd FileType vimwiki nnoremap zb :ZettelBackLinks<CR>
    autocmd FileType vimwiki nnoremap zf :NV! \(<C-R>=expand("%:t:r")<CR><CR>
    autocmd FileType vimwiki nmap T <Plug>ZettelYankNameMap
    autocmd FileType vimwiki xmap z <Plug>ZettelNewSelectedMap
    autocmd FileType vimwiki nmap gZ <Plug>ZettelReplaceFileWithLink
augroup END

nnoremap <leader>zn :ZettelNew<SPACE> "create new Zettel
nnoremap <leader>zb :ZettelBackLinks<CR> "create ZettelBacklinkgs
nnoremap <leader>zo :ZettelOpen<CR> "open Zettel
nnoremap <leader>zf :NV! \(<C-R>=expand("%:t:r")<CR><CR> "search Backlinks

Any Idea what I am doing wrong?

michal-h21 commented 2 years ago

You don't have the visual mode mapping in your configuration. Try to add this to the augroup:

  autocmd FileType vimwiki xmap [[ <Plug>ZettelTitleSelectedMap

Note that other users reported problems with [[ in visual mode, so maybe try other key sequence.

tbsmn commented 2 years ago

Thank you very much! Got it working but I had to change the mapping with [[ it won't work.

michal-h21 commented 2 years ago

I've changed the default mapping to g[, as you are the second user for whom it didn't work.

folofjc commented 2 years ago

I've changed the default mapping to g[, as you are the second user for whom it didn't work.

Could you put this in the doc? I was searching for this in the doc and didn't see it and just found this issue! Thanks!