Combined compilation of compilation and run Vim

I have the following mapping in my .vimrc.

:nmap <F5> :<CU>make %:r && ./%:r<CR> 

I press F5 in VIM and it compiles, exits VIM and runs my code. When the program terminates, it asks me to "press ENTER or enter a command to continue." Then it displays me on a blank screen with the text (1 of 5): and with the same "press Enter or enter a command to continue." I press Enter and it finally brings me back to VIM. This behavior is consistent across the board. Is there a way to remove either or both of these cases? Perhaps if after completing the program press ENTER twice? If so, how?

EDIT: So, I realized that adding two more <CR> doesn't quite solve the problem. As soon as the program terminates, it IMMEDIATELY returns to VIM, and I do not have time to view the output. Can I do a ME wait match to press the first input, and automatically press the second ENTER after?

+4
source share
3 answers

Will this work:

nmap <F5> :<CU>silent make %:r<CR>:redraw!<CR>:!./%:r<CR>

A longer solution, but it also allows you to see errors ( link ):

 :function! MakeAndRun() : silent make %:r : redraw! : if len(getqflist()) == 1 : !./%:r : else : for i in getqflist() : if i['valid'] : cwin : winc p : return : endif : endfor : endif :endfunction :nmap <F5> :call MakeAndRun()<cr> 
0
source

Yes and yes (you answered your question):

 :nmap <F5> :<CU>make %:r && ./%:r<CR><CR> 
+1
source

For me, this works great:

 " Compile noremap <F4> :<CU>silent make<CR>:redraw!<CR> " Automatically open, but do not go to (if there are errors) the quickfix / " location list window, or close it when is has become empty. autocmd QuickFixCmdPost [^l]* nested cwindow autocmd QuickFixCmdPost l* nested lwindow 

It compiles and goes straight to vim, showing the quickfix window. The gap is not included.

0
source

Source: https://habr.com/ru/post/1400314/


All Articles