1

When I try to run a file with Neovim it shows me this:

screenshot

It doesn't allow me to type any input. How can I type some input using Neovim ?

This is my script for compiling:

g++ -static -DLOCAL -lm -s -x c++ -Wall -Wextra -O2 -std=c++17 -o $1 $1.cpp 

This are my commands in Neovim for compiling and running a cpp file:

autocmd filetype cpp nnoremap <F9> :w <bar> !build.sh %:r <CR> 
autocmd filetype cpp nnoremap <F10> :!./%:r<CR>

Here is my init.vim.

I have windows 10 with WSL. Thank you!

2

1 Answer 1

0

When you run an external command using :! in NeoVim, it doesn't get connected to a terminal, which means it can't take input from the user.

From :help :! in NeoVim:

The command runs in a non-interactive shell connected to a pipe (not a terminal). Use :terminal to run an interactive shell connected to a terminal.

Note that this is NeoVim-specific. In regular Vim, running a command under :! runs in a terminal, which means it can take input from the user. This is intended behavior in NeoVim, it's that way by design.

Instead of :!, you can instead use the :terminal command to run your binary inside a NeoVim window.

For example, this command should take care of it:

autocmd filetype cpp nnoremap <silent> <buffer> <F10> :split | execute 'terminal ./%:r' | startinsert<CR>

I also added <silent> to the mapping, so that it doesn't print the Ex command before executing it (usually a good idea) and also <buffer>, since the mapping is set based on filetype, it should only apply to buffers of that specific filetype (and not be a global mapping, which would apply to all buffers and would potentially be overwritten by the mapping for the last filetype you opened.)

1
  • 1
    Thank you very much, sir ! Commented Jun 6, 2021 at 18:46

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.