我修改了以下代码,该代码应将视觉选择发送到我的Neovim终端。
function! REPLSend(lines)
echo a:lines
" call jobsend(g:last_terminal_job_id, add(a:lines, ''))
" call chansend(g:last_terminal_job_id, add(a:lines, ''))
call chansend(g:last_terminal_job_id, a:lines)
endfunction
command! REPLSendLine call REPLSend([Get_visual_selection()])
" command! REPLSendLine call Get_visual_selection()
nnoremap <silent> <f6> :REPLSendLine<cr>
function! Get_visual_selection()
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
let lines = insert(lines, "%cpaste")
return join(lines, "\n")
endfunction
当我使用f6
调用代码时,Get_visual_selection
正确地获取了选定的文本,但是REPLSend(lines)函数似乎没有被调用。我在做什么错了?
答案 0 :(得分:0)
我喜欢使用这样的映射:
" sending blocks (clearing previous output)
noremap <leader>tb (y)<C-w>wpa<C-l><CR><C-\><C-n><C-w>p)
" sending lines
noremap <leader>tl Vy<C-w>wpa<CR><C-\><C-n><C-w>pj
" sending visual selection
noremap <leader>ts y<C-w>wpa<CR><C-\><C-n><C-w>p
使用这些映射,终端缓冲区应该在下一个窗口位置,但是,例如,如果终端缓冲区始终在右侧,则可以将<c-w>w
映射到<c-w>j
。