Initial window:
My expectation: to copy whole or a part of python code in the right window into the left window's python terminal and execute.
My .vimrc
setting:
function! CopyPasteBuffer()
normal gg"*yG
wincmd p
call feedkeys("\<C-W>\"*")
endfunction
nnoremap <leader>pp :call CopyPasteBuffer()<CR>
function! CopyRun() range
exe a:firstline . "," . a:lastline . "y*"
wincmd p
call feedkeys("\<C-W>\"*")
endfunction
command! -range PassRange <line1>,<line2>call CopyRun()
nnoremap ,pr :CopyRun<cr>
In vim's normal mode in the right window, I type ,pp
(leader configured as ,
), all python statements in the right pushed into python terminal in the left and executed.
Now I want to execute a range of python statements in the right, move cursor in the right window and enter into ex mode, and type 1,3pr
, the lines are executed but not in my desired python terminal such as the above image shows.
How to fix my vimscript?
After following Maxim Kim
's suggestion,1,3PassRange
works, I rewrite the mapping as nnoremap ,pr :PassRange<cr>
, why can't 1,3pr
get the same effect as 1,3PassRange
?
Following Maxim Kim
's instruction, I want to make more progress, toggle from uppercase to lowercase and from lowercase to uppercase, it is inconvenient.
Without range as argument:
nnoremap <leader>pp :call CopyPasteBuffer()<CR>
I can type ,pp
without uppercase to get desired result.
With range as argument:
command! -range Xr <line1>,<line2>call CopyRun()
1,3Xr
can work,i want to make ,1,3re
map as 1,3Xr
and call CopyRun
,so add new mapping
map <leader>,re :Xr<cr>
It can't work, how to fix it?
:call term_list()[0]->term_sendkeys(getline('.') .. "\<CR>")
to send current line to a terminal window.