I'm trying to make a keyboard binding in Neovim that would send a selected block to the opened Neovim terminal. I've used these answers as guidelines https://vi.stackexchange.com/a/3390/3405 https://stackoverflow.com/a/6271254/859391

Though when i'm trying to call the command with a Visual Line selected I keep getting the No Range Allowed error. Am I missing something obvious?

function! s:get_visual_selection()
  " Why is this not a built-in Vim script function?!
  let [lnum1, col1] = getpos("'<")[1:2]
  let [lnum2, col2] = getpos("'>")[1:2]
  let lines = getline(lnum1, lnum2)
  let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
  let lines[0] = lines[0][col1 - 1:]
  return join(lines, "\n")

augroup Terminal
  au TermOpen * let g:last_terminal_job_id = b:terminal_job_id
augroup END

function! REPLSend(lines)
  call jobsend(g:last_terminal_job_id, lines[0])
  call jobsend(g:last_terminal_job_id, "\r") " needed for the way REPL handles the input

command! REPLSendLine call REPLSend([s:get_visual_selection()])
vnoremap <silent> <leader>l :REPLSendLine<cr>
" leader is <Space>

1 Answer 1


I'm not sure, but I think that when you hit <leader>l to call :REPLSendLine, Vim automatically inserts the visual range '<,'>, and since your command is not defined with the attribute -range, it raises an error.

In your visual mapping, you should probably add the keycode <C-U> to remove the visual range (it won't affect the marks '< and '>, they will still be valid inside s:get_visual_selection()):

vnoremap <silent> <leader>l :<C-U>REPLSendLine<cr>

Also, maybe you could try removing the inline comment " needed for the way REPL handles the input and put it on a separate and dedicated line.

  • Thank you. ":<C-U>" did the trick. Also, the comment I've added it only for this question, to make it more clear what I was going for.
    – 6D65
    Commented Apr 2, 2016 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.