compile directly from vim

后端 未结 6 1178
独厮守ぢ
独厮守ぢ 2021-01-31 05:43

I\'d like to compile cpp file w/o turning off vi.
I know the :!g++ file.cpp but I prefer :make so I added this line in .vimrc file

6条回答
  •  再見小時候
    2021-01-31 06:25

    It can be easily achieved by the use of key maps.

    First open up your vimrc file and these lines to the file,

    autocmd filetype cpp nnoremap  :!g++ % -ggdb -o %:r 
    autocmd filetype cpp nnoremap :!g++ % -ggdb -o %:r && ./%:r 
    

    The first line maps the key F4 to compiling the file. The second line maps the key F5 to compile and run.

    If you use gdb frequently then this may also come handy.

    autocmd filetype cpp nnoremap :!g++ % -ggdb -o %:r && gdb -tui %:r 
    

    This line maps the key F10 to compile and start gdb

    Hope this helps.

提交回复
热议问题