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:
"{register}p
<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?
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.
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.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With