terrychou / iVim

A vim port to iOS.
601 stars 34 forks source link

Unexpected behaviour with system clipboard #196

Open pdavisonreiber opened 3 years ago

pdavisonreiber commented 3 years ago

I was interested in using iVim to write and edit Markdown, so I thought I would implement a custom keyboard binding for inserting a Markdown link. What I wanted to achieve was to be able to copy a link to the iOS clipboard, then go into visual mode in vim, select the link text, and then hit my custom key binding to convert that to a Markdown link with the URL from the clipboard.

After trying several different approaches myself, I came across this post which suggested the command

autocmd FileType markdown vnoremap <c-a> <Esc>`<i[<Esc>`>la](<Esc>"*]pa)<Esc>

I added this into my .vimrc file, but it doesn’t seem to be working, and I think the reason why is some strange behaviour with the registers.

I used the :reg command to investigate what was going on, and I think I’ve figured it out. When I copy the link I want to insert to the system clipboard, it appears in the "* register, but then when I go into visual mode and just select the link text, it immediately overwrites the "* register with the selection. I haven't yanked or deleted, just selected. So when I run the keybinding I always end up with [link text](link text).

Is this intended behaviour? I don't mind that deleting or yanking automatically copies to the system clipboard, as a convenience – although I wonder too if that is intended behaviour since it doesn't work the same way with pasting.

Thanks for your help. The more I use iVim, the more impressed I am with how integrated it is with native iOS features. Keep up the good work!

terrychou commented 3 years ago

I think it has something to do with the a flag (Autoselect :h go-a) in the guioptions. Right now, I am not sure how it managed to sneak into the default setting. However, for a temporary workaround for this issue, you can use set guioptions-=a to remove it.

pdavisonreiber commented 3 years ago

Thanks! I’ve added that to my .vimrc file and that seems to have fixed it.