Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tbsmn opened this issue May 7, 2021 · 6 comments
Closed

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

tbsmn opened this issue May 7, 2021 · 6 comments

Comments

@tbsmn
Copy link

tbsmn commented May 7, 2021

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
Copy link
Owner

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
Copy link
Author

tbsmn commented Jun 24, 2022

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
Copy link
Owner

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
Copy link
Author

tbsmn commented Jun 27, 2022

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

@tbsmn tbsmn closed this as completed Jun 27, 2022
@michal-h21
Copy link
Owner

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

@folofjc
Copy link

folofjc commented Aug 2, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants