I've recently switched to neovim (NVIM v0.4.4) from vim.
Previously in my .vimrc file I had these two mappings that allowed me to run javascript and c++ files inside vim.
nnoremap <f4> :!node %<CR>
nnoremap <f9> :!clear && g++ -std=c++17 % -Wall -g -o %.out && ./%.out<CR>
But in neovim if I use them some programs don’t print things correctly and don’t accept user input. For example this JavaScript code doesn't work:
process.stdin.pipe(process.stdout);
And the output I get is:
:! node index.js
[No write since last change]
Press ENTER or type command to continue
then if I press any key it just closes the command panel.
After that I found the following code snippet that allowed me to open the terminal in neo-vim.
"open terminal on ctrl+n"
function! OpenTerminalVartically()
vsplit term://bash
endfunction
function! OpenTerminalHorizontally()
split term://bash
resize 10
endfunction
nnoremap <c-n> :call OpenTerminalHorizontally()<CR>
nnoremap <c-m> :call OpenTerminalVartically()<CR>
At first it just opened the terminal below the code editor. Then I figured out a way to open it vertically by modifying the function.
As I'm new to vim I don't know much about vim-scripting. Is there any way I can do the following:
nnoremap <f4> :call OpenTerminalVartically(node %)<CR>
" I just want to pass the command in the function and execute it in the newly opened terminal.
to run the current JavaScript file? Could you kindly give me some hint how can I accomplish this?
:split term://node
?:call myfunc(%)
and then in the function you build a command with:execute
....something likeexe ":split term://node " . a:filename
.