How can I create a keymap to send the visual selection/current line to a vim terminal window?
I opened a normal vim window (containing only the line echo test
) and a vim terminal window and tried recording a macro and figuring it out from there, but ran into problems:
I ran
qqY<C-W>w<C-Shift-V><C-W>wq
but the resulting macro simple containedecho test
as opposed to a paste command (I gotY^Ww<80>PSecho test^M<80>PE^Ww
)I tried to paste in the terminal window normal mode via
qqY<C-W>w<C-\><C-N>p<C-W>wq
but the paste didn't work and I got the error messageCannot make changes, 'modifiable' is off
. Tryingset modifiable
I gotCannot make a terminal with running job modifiable: modifiable
UPDATE:
Following the answer by Christian Brabandt below, I added the lines
nnoremap <F9> Y<C-W>w<C-W>"0<C-W>w
xnoremap <F9> y<C-W>w<C-W>"0<C-W>w
to my .vimrc
. This works almost as desired but has problems with whitespace and multiple lines. For example, if I select
if False:
pass
print('Done')
in VISUAL LINE mode, and press F9 to execute it in a terminal window running ipython
, the ipython terminal shows
In [1]: if False:
...: pass
...: print('Done')
...:
This is due to ipython
's autoindentation, which can be turned off via %autoindent
or by starting ipython
with the option --no-autoindent
. Alternatively, ipython
's %paste
command could be used. I would be nonetheless interested in a vim hack that behaves more like <C-Shift-V>
.