How can I insert NeoVim registers in terminal mode?

When using the NeoVim :terminal function, I would like to be able to insert text from the register.

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

  • in normal mode: "{register}p
  • in insert mode: <Cr>{register}

I can not get these commands to work as I would like in the terminal buffer. When the terminal buffer is in normal mode, I can use "{register}p to add the contents of the register at the end of the current command line. Sometimes I would like to insert text at the beginning of the current command line or halfway through it, and it seems that with this command there is no way to do this.

It seems to me that this should be possible by switching to terminal mode (which seems to be a buffer terminal equivalent to Insert mode) and using the <Cr>{register} command. But ctrl + r is sent directly to my shell. I use a bash shell that maps these keys to a reverse lookup function, so I am at this prompt:

 (reverse-i-search)`': 

Is there a way I can use <Cr>{register} in terminal mode?

+6
source share
2 answers

Nvim is conservative with respect to handling any keys (except <C-\><CN> ) in terminal mode, so CTRL-R is not processed by default. In addition, Nvim does not know 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> <CR> '<C-\><CN>"'.nr2char(getchar()).'pi' 
+5
source

Actually there is no need to insert control characters in a configuration. You can let Nvim cancel them for you.

 "Enable CTRL-V in terminal mode tnoremap <expr> <CR> '<C-\><CN>"'.nr2char(getchar()).'pi' 
+2
source

Source: https://habr.com/ru/post/1014131/


All Articles