Sending visual selection to neovim terminal
I have adapted the following code which should send the visual selection to my Neovim terminal.
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
When I invoke the code with f6
, Get_visual_selection
correctly gets the text selected but the REPLSend(lines) function does not appear to get called. What am I doing wrong?
vim neovim
add a comment |
I have adapted the following code which should send the visual selection to my Neovim terminal.
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
When I invoke the code with f6
, Get_visual_selection
correctly gets the text selected but the REPLSend(lines) function does not appear to get called. What am I doing wrong?
vim neovim
Debug it step by step. First, try:call REPLSend([Get_visual_selection()])
. If that works try:REPLSendLine
.
– phd
Nov 26 '18 at 17:28
Thanks. Both:call REPLSend([Get_visual_selection()])
and:REPLSendLine
works. Seems to be a problem withnnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Make itnnoremap <f6> :REPLSendLine<cr>
(remove<silent>
) to see the error.
– phd
Nov 27 '18 at 10:04
@phd: removed<silent>
. Checkedmessages
but nothing there. How do I see the error?
– pdoak
Nov 28 '18 at 15:00
I trimmed functionREPLSend
to justecho a:lines
(I havevim
, notneovim
) and the code works for me, even after I pressed<F6>
. I'm puzzled.
– phd
Nov 28 '18 at 15:13
add a comment |
I have adapted the following code which should send the visual selection to my Neovim terminal.
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
When I invoke the code with f6
, Get_visual_selection
correctly gets the text selected but the REPLSend(lines) function does not appear to get called. What am I doing wrong?
vim neovim
I have adapted the following code which should send the visual selection to my Neovim terminal.
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
When I invoke the code with f6
, Get_visual_selection
correctly gets the text selected but the REPLSend(lines) function does not appear to get called. What am I doing wrong?
vim neovim
vim neovim
asked Nov 26 '18 at 15:55
pdoakpdoak
339211
339211
Debug it step by step. First, try:call REPLSend([Get_visual_selection()])
. If that works try:REPLSendLine
.
– phd
Nov 26 '18 at 17:28
Thanks. Both:call REPLSend([Get_visual_selection()])
and:REPLSendLine
works. Seems to be a problem withnnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Make itnnoremap <f6> :REPLSendLine<cr>
(remove<silent>
) to see the error.
– phd
Nov 27 '18 at 10:04
@phd: removed<silent>
. Checkedmessages
but nothing there. How do I see the error?
– pdoak
Nov 28 '18 at 15:00
I trimmed functionREPLSend
to justecho a:lines
(I havevim
, notneovim
) and the code works for me, even after I pressed<F6>
. I'm puzzled.
– phd
Nov 28 '18 at 15:13
add a comment |
Debug it step by step. First, try:call REPLSend([Get_visual_selection()])
. If that works try:REPLSendLine
.
– phd
Nov 26 '18 at 17:28
Thanks. Both:call REPLSend([Get_visual_selection()])
and:REPLSendLine
works. Seems to be a problem withnnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Make itnnoremap <f6> :REPLSendLine<cr>
(remove<silent>
) to see the error.
– phd
Nov 27 '18 at 10:04
@phd: removed<silent>
. Checkedmessages
but nothing there. How do I see the error?
– pdoak
Nov 28 '18 at 15:00
I trimmed functionREPLSend
to justecho a:lines
(I havevim
, notneovim
) and the code works for me, even after I pressed<F6>
. I'm puzzled.
– phd
Nov 28 '18 at 15:13
Debug it step by step. First, try
:call REPLSend([Get_visual_selection()])
. If that works try :REPLSendLine
.– phd
Nov 26 '18 at 17:28
Debug it step by step. First, try
:call REPLSend([Get_visual_selection()])
. If that works try :REPLSendLine
.– phd
Nov 26 '18 at 17:28
Thanks. Both
:call REPLSend([Get_visual_selection()])
and :REPLSendLine
works. Seems to be a problem with nnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Thanks. Both
:call REPLSend([Get_visual_selection()])
and :REPLSendLine
works. Seems to be a problem with nnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Make it
nnoremap <f6> :REPLSendLine<cr>
(remove <silent>
) to see the error.– phd
Nov 27 '18 at 10:04
Make it
nnoremap <f6> :REPLSendLine<cr>
(remove <silent>
) to see the error.– phd
Nov 27 '18 at 10:04
@phd: removed
<silent>
. Checked messages
but nothing there. How do I see the error?– pdoak
Nov 28 '18 at 15:00
@phd: removed
<silent>
. Checked messages
but nothing there. How do I see the error?– pdoak
Nov 28 '18 at 15:00
I trimmed function
REPLSend
to just echo a:lines
(I have vim
, not neovim
) and the code works for me, even after I pressed <F6>
. I'm puzzled.– phd
Nov 28 '18 at 15:13
I trimmed function
REPLSend
to just echo a:lines
(I have vim
, not neovim
) and the code works for me, even after I pressed <F6>
. I'm puzzled.– phd
Nov 28 '18 at 15:13
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53484797%2fsending-visual-selection-to-neovim-terminal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53484797%2fsending-visual-selection-to-neovim-terminal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Debug it step by step. First, try
:call REPLSend([Get_visual_selection()])
. If that works try:REPLSendLine
.– phd
Nov 26 '18 at 17:28
Thanks. Both
:call REPLSend([Get_visual_selection()])
and:REPLSendLine
works. Seems to be a problem withnnoremap <silent> <f6> :REPLSendLine<cr>
– pdoak
Nov 27 '18 at 9:27
Make it
nnoremap <f6> :REPLSendLine<cr>
(remove<silent>
) to see the error.– phd
Nov 27 '18 at 10:04
@phd: removed
<silent>
. Checkedmessages
but nothing there. How do I see the error?– pdoak
Nov 28 '18 at 15:00
I trimmed function
REPLSend
to justecho a:lines
(I havevim
, notneovim
) and the code works for me, even after I pressed<F6>
. I'm puzzled.– phd
Nov 28 '18 at 15:13