My current keybinding for compiling cpp files is:
autocmd filetype cpp nnoremap <F2> :!g++ -g %<CR>:!./a.out<CR>
When I press F2, vim escapes to the shell and a.out executes well uptil taking input. But, it does not wait for output and returns back to the editor. This never happened earlier when I typed the command manually, vim used to wait for me to read the output and then I got a line saying: "Press ENTER or type command to continue."
[Update] I changed the command to:
autocmd filetype cpp nnoremap <F2> :!g++ -g %<CR>:!./a.out
Now when I press F2, it finally writes :!./a.out
below and I manually press Enter. This time it actually waits for me in the terminal. Why is this happening?
Try reproducing by using both the keybindings this one and the former.
:![cmd]
(especially in mappings) because I'm not really smart enough to remember all the escaping rules and such, and sometimes it behaves unexpected. You can use a single shell command withnnoremap <F2> :!g++ -g % && ./a.out<CR>
.