I've created the following script on my vimrc
file:
function! ExecuteOnTerminal()
if (&ft=='javascript')
:%terminal node
elseif (&ft=='sh')
:%terminal bash
elseif (&ft=='python')
:%terminal python3
endif
endfunction
map <F6> :silent call ExecuteOnTerminal()<CR>
It works fine... It detects the type of the file that I'm editing and when I press F6 and I'm in Normal mode it will execute the current file on a splited terminal window. However, I'd like to go beyond this functionality and detect if I currently have selected lines on Vim. if I do, I'd like to execute only the current selected lines. If I don't, I'd like to execute the entire file (executing the entire file is the current behavior).
When I try to press F6 with this script I receive the error No range allowed
. Is there any way of detecting if I'm in visual mode and executing a different command for it? Or would it be better creating a new command?