I have an open ipython
terminal open, and I'd like to paste the visual selection to it, with prepending "%cpaste"
and appending "--"
This is what I came up with
function! VisualSelection()
if mode()=="v"
let [line_start, column_start] = getpos("v")[1:2]
let [line_end, column_end] = getpos(".")[1:2]
else
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
end
if (line2byte(line_start)+column_start) > (line2byte(line_end)+column_end)
let [line_start, column_start, line_end, column_end] =
\ [line_end, column_end, line_start, column_start]
end
let lines = getline(line_start, line_end)
if len(lines) == 0
return get_line(line('.')) endif
let lines[-1] = lines[-1][: column_end - 1]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
vnoremap <silent> <F7> :call term_sendkeys(term_list()[0], "%cpaste\n".VisualSelection())."\n--\n")<cr>
Unfortunately, for some reason the string "cpaste"
gets sent multiple times, and the rest is sent after that.
Any ideas what could be the problem ?