Vim setting 'map <F12>:! python% <cr> 'automatically returns to vim after execution in terminal

I added map<F12> :!python %<cr> to ~/.vimrc . However, it automatically terminates after executing this command when I press the <F12> key. In the normal case, it should stop at the line Press ENTER or type command to continue , but in my case, just skip this line and go back to vim. It looks like someone is pressing ENTER secretly. The most amazing thing is that this happens only in the terminal. when I type `:! python% 'manually or using gvim, everything is fine. I do not know how to fix this problem.

+4
source share
1 answer

It is possible that the terminal version redraws the screen before you can read the message. You can try setting 'lazyredraw' to delay the redraw.

A workaround could be to set 'lazyredraw' and add a call to getchar() to the display:

  function! RunPython() let s:save_lz = &lazyredraw " save 'lazyredraw' setting set lazyredraw !python % call getchar() " stop waiting pressing a key let &lazyredraw = s:save_lz " restore 'lazyredraw' endfunction map <F12> :call RunPython()<CR> 

EDIT:

You can also consider using a plugin for this task, because "SingleCompile: make it more convenient to compile or run a single source file . "

+3
source

All Articles