Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I paste NeoVim registers in terminal mode?

When using NeoVim's :terminal feature, I'd like to be able to paste text from a register.

When working with a standard text buffer, I frequently use two methods to paste text from a register:

  • in Normal mode: "{register}p
  • in Insert mode: <C-r>{register}

I can't get these commands to work the way I'd like them to in a terminal buffer. When the terminal buffer is in Normal mode, I can use "{register}p to append the contents of a register at the end of the current command line. Sometimes I'd like to insert text at the start of the current command line, or midway through it, and it seems like there's no way of doing that using this command.

It occurs to me that this should be possible by switching to Terminal mode (which seems to be the terminal buffer equivalent to Insert mode) and using the <C-r>{register} command. But the ctrl+r is sent directly to my shell. I'm using the bash shell, which maps these keys to the reverse search feature, so I find myself looking at this prompt:

(reverse-i-search)`':

Is there any way that I can use the <C-r>{register} in Terminal mode?

like image 799
nelstrom Avatar asked Jan 16 '17 17:01

nelstrom


People also ask

How do I copy and paste on NeoVim?

We use Ctrl+Shift+C for pasting the contents from the clipboard to the shell. * : This register stores the currently selected item in the system. we generally use Ctrl+Shift+s for pasting the contents of the 'select' clipboard to the shell.

How do I paste in vim in terminal?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

Does NeoVim work in terminal?

In NeoVim, we can launch a terminal emulator by running the :terminal command. Now we're running a shell inside of our text editor. We can run commands in the shell as usual. When we exit the shell, the terminal emulator closes and NeoVim switches us back to a regular buffer.

How do I paste a register in Vim?

To paste the content of this register, the logic is the same: "rp . You are p asting the data that is in this register. You can also access the registers in insert/command mode with Ctrl-r + register name, like in Ctrl-r r . It will just paste the text in your current buffer.


1 Answers

Nvim is conservative about handling any keys (except <C-\><C-N>) in terminal-mode, so CTRL-R isn't handled by default. Also, Nvim has no idea about which application is running inside :terminal, so p just blindly sends text to the input stream.

Having said that, you can use :tnoremap to get a similar effect for CTRL-R:

:tnoremap <expr> <C-R> '<C-\><C-N>"'.nr2char(getchar()).'pi'
like image 58
Justin M. Keyes Avatar answered Sep 19 '22 09:09

Justin M. Keyes