Vim [compile and] run shortcut

后端 未结 6 692
醉梦人生
醉梦人生 2020-12-12 17:21

Basically what I want is a keyboard shortcut in vim that lets me [compile and] run the currently being edited C, C++ or Python program. In psuedocode:

when a         


        
6条回答
  •  感情败类
    2020-12-12 17:51

    I know I came here 7 years later. I tried the code of other answers and the result didn't satisfied me, so I tried this:

    autocmd filetype cpp nnoremap  :wterm ++shell g++ %:p -o %:p:r && %:p:r
    

    When F9 is pressed, it (like all the answers above) compiles and executes the current file. The output is displayed in a :terminal section splitted screen. You can change the g++ command to run another language code.

    It is saved in a gist, with another mapping to display the output, also in a splitted section, but in a new file, so you can save the output.

    Hopefully it could help someone.

提交回复
热议问题