michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
559 stars 73 forks source link

T not working to yank the link #8

Closed Smingvin closed 4 years ago

Smingvin commented 4 years ago

Hi, Everything works great except T to yank the current zettel as a md link. Nothing happens when I press T.

I'm not sure what kind of info to give you to help.

michal-h21 commented 4 years ago

That means that the current Zettel doesn't have title. The title is usually created automatically when you use vim-zettel functions. It should look like:

---
title: Title
date: 2020-02-11 15:32
---

When the title cannot be found, the yanked link contains empty string for title and it is being concealed by Vimwiki. I've added new variable g:zettel_no_title, it contains No title by default. It will be used instead of empty titles from now. But the correct solution is to use titles.

Smingvin commented 4 years ago

Hey thanks for getting back so quickly. Lat me say again that this is an awesome plugin. But unfortunately, T doesn't work for me even when I have a title. I tried it a couple of times. Nothing happens. When I paste I just get whatever I yanked previously. Let me know if I can provide any additional info.

michal-h21 commented 4 years ago

Ah, that is strange. It happens in the Markdown mode? Don't you get any error messages? Does the following command yank the link?:

 :ZettelYankName

If not, what does the following command print?:

  :echom (zettel#vimwiki#get_title(expand("%"))) 

It should print title of the current Zettel

Smingvin commented 4 years ago

Indeed it prints the title of the current Zettel.

ZettelYankName does nothing, no error message. (although vim recognizes that such a command exists: ZettelY + TAB expands into ZettelYankName)

I am in Markdown mode.

Maybe I made some mistake in the setup.

I didn't use Vundle. I installed all the necessary plugins manually by cloning the repositories in the bundle folder where most of my other vim plugins are, and added these to my vimrc:

" for fzf
set rtp+=/usr/local/opt/fzf

" for vim-zettel
set runtimepath^=~/.vim/bundle/vim-zettel
set runtimepath^=~/.vim/bundle/fzf.vim
let g:zettel_format = "%y%m%d-%H%M"
let g:zettel_fzf_command = "ag"
let g:zettel_default_mappings = 0 
augroup filetype_vimwiki
  autocmd!
  autocmd FileType vimwiki imap <silent> [[ [[<esc><Plug>ZettelSearchMap
  autocmd FileType vimwiki nmap T <Plug>ZettelYankNameMap
  autocmd FileType vimwiki xmap z <Plug>ZettelNewSelectedMap
  autocmd FileType vimwiki nmap gZ <Plug>ZettelReplaceFileWithLink
augroup END

And I don't have a clue what these .tpl pathnames refer to, here's what I added to that section:

let g:vimwiki_list = [{'path': '~/Dropbox/vimwiki/', 'template_path': '~/vimwiki/templates/','template_default': 'default', 'syntax': 'markdown', 'ext': '.md', 'custom_wiki2html': 'vimwiki_markdown', 'zettel_template': "~/mytemplate.tpl", 'template_ext': '.tpl'}]

let g:zettel_options = [{},{"front_matter" : {"tags" : ""}, "template" :  "~/mytemplate.tpl"}]

Btw, fzf, [[, zettelnew, z -- they all work as they should.

michal-h21 commented 4 years ago

So the title detection function works correctly, it just isn't executed using the default mapping. Maybe there is conflict with another plugin or configuration? Does the following work?:

 :nmap H :ZettelYankName<cr> 

It uses H instead of T

You don't need this in your .vimrc as it uses just the default values. I am not sure if it causes problems, but it is not necessary:


let g:zettel_format = "%y%m%d-%H%M"
let g:zettel_fzf_command = "ag"
let g:zettel_default_mappings = 0 
augroup filetype_vimwiki
  autocmd!
  autocmd FileType vimwiki imap <silent> [[ [[<esc><Plug>ZettelSearchMap
  autocmd FileType vimwiki nmap T <Plug>ZettelYankNameMap
  autocmd FileType vimwiki xmap z <Plug>ZettelNewSelectedMap
  autocmd FileType vimwiki nmap gZ <Plug>ZettelReplaceFileWithLink
augroup END
Smingvin commented 4 years ago

Removed all that stuff from vimrc and tried the nmap to H. It does call ZettelYankName, but yanks nothing. So, :echom (zettel#vimwiki#get_title(expand("%"))) works But ZettelYankName doesn't, neither with default or custom mapping.

michal-h21 commented 4 years ago

Does the following command print formatted link to the current Zettel?:

   :echom  zettel#vimwiki#get_link(expand("%"))

This link is then saved in the unnamed register, so this can be also issue. What does ""p in the normal mode paste after running :ZettelYankName?

Smingvin commented 4 years ago

You got it! The command does indeed print the formatted link, and ""p is pasting it. This is good enough for me. If you have any clue why it doesn't get in whichever is the default clipboard register, let me know but I'm happy as it is. Thanks for the useful plugin!

Only thing in my vimrc that seems to be related to this is:

"set clipboard to work across windows
set clipboard=unnamed
michal-h21 commented 4 years ago

The ZettelYankName uses the unnamed register, so this could be the issue, although the set clipboard=unnamed doesn't change the default behaviour for me.

I've made a small change to the code, but doesn't expect that it changed anything, it still uses unnamed register.

nate-double-u commented 4 years ago

I just wanted to +1 @Smingvin 's issue.

I have the same problem and vimrc(init.vim) line: set clipboard=unnamed

In normal mode T yanks the link to the unnamed register, then I can put in insert mode with: Ctrl-R " (was a bit confusing on the put as the " shows up, indicating the need for a second keystroke -- but actually typing " does put the link.)

""p also pastes it from normal mode.

mdoliwa commented 4 years ago

Same here. Without set clipboard=unnamed it works fine. But when it's in my vimrc I have to use commands from @hackabletype comment.

I'm using neovim.

michal-h21 commented 4 years ago

@hackabletype @mdoliwa @Smingvin I've modified the code to detect the clipboard type, so it should copy the note link to the correct register now.

nate-double-u commented 4 years ago

Sorry for the delay, your fix works for me @michal-h21

Thanks!

michal-h21 commented 4 years ago

Great! So we can close this issue :)