Q:

Mapping a command in Visual Mode results in error E481: No range alllowed

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")
endfunction

augroup Terminal
  au!
  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
endfunction

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

A:

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.

