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

How to yank & paste in nmap? #600

Closed
AdrienLemaire opened this issue Feb 3, 2020 · 8 comments
Closed

How to yank & paste in nmap? #600

AdrienLemaire opened this issue Feb 3, 2020 · 8 comments

Comments

@AdrienLemaire
Copy link

AdrienLemaire commented Feb 3, 2020

On firefox/chrome, I use yomichan to see japanese translations.
Since it has no support for webkit2gtk, I'm trying to find an alternative solution:

Manual operation:

  • select word and Y (yank/copy text)
  • t to open in new tab
  • jisho<tab> to find a previous jisho search, then remove search part
  • C-v twice to paste the yanked text in the search url
  • Enter

Automated operation:

shortcut-add j=https://jisho.org/search/$0
nnoremap <C-J> Y :tabopen j <C-v><C-v><CR>

What I'm trying to do is auto yank and open jisho page with selected text. But my map isn't working.

Example: Selecting text '大幅' and pressing Ctrl-j

Expected:

  • A new tab opens with https://jisho.org/search/大幅

What happens:

  • 2 tabs open, each with https://jisho.org/search/

Looks like the <C-v> part of the nnoremap doesn't work. How would you do it @fanglingsu ?

@fanglingsu
Copy link
Owner

@AdrienLemaire I do also not understand why <C-V> does not work but you could use <C-R>" instead which writes the last yanked register.
:nnoremap <C-J> Y:tabopen j <C-R>"<CR>

@fanglingsu
Copy link
Owner

@AdrienLemaire I though a bit about the <C-V> this does not work because it is no vimb command. The first <C-V> is a command which stops key processing logic of vimb so the second CTRL-V is interpreted by webkit or GTK to past the clipboard. If the :nnormap is applied there is no logic which would turn <C-V> into a keyevent that could be used by webkit. So it does not work.

@AdrienLemaire
Copy link
Author

AdrienLemaire commented Feb 9, 2020

@fanglingsu lovely, I'm almost there :)

shortcut-add j=https://jisho.org/search/$0
nnoremap <C-J> Y :tabopen j <C-R>"<CR>

It now opens the correct page, but still open 2 tabs instead of one.
I can't figure out why 2 tabs are being open here.

If I use nnoremap <C-J> Y :tabopen j <C-R>" then highlight text and press C-j-Enter, it works as expected.

@fanglingsu
Copy link
Owner

@AdrienLemaire That's strange! I can reproduce this and I can't guess why this should happen. I'll have to debug this.

@fanglingsu
Copy link
Owner

fanglingsu commented Feb 18, 2020

@AdrienLemaire For me this works if I strip the space between the yank Y and the :tabopen.

nnoremap <C-J> Y:tabopen j <C-R>"<CR>

But I'm far away from getting the reason for this behaviour.

@AdrienLemaire
Copy link
Author

Thanks for figuring out the trick! This is perfect now :)

@fanglingsu
Copy link
Owner

The issue seems to be related to #546.

@fanglingsu
Copy link
Owner

@AdrienLemaire I think it is now solved.

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

2 participants