user7274303
user7274303

Reputation:

Executing C code with F5 key in Vim

I want to save and execute my codes that's written in C programming language with just pressing F5 key in vim (in normal mode).

So I added this line to .vimrc file :

:autocmd FileType c nnoremap <F5> <Esc>:w!<CR>:!clear && gcc %<CR> && ./<CR>

But it doesn't work ! (It's make .Out file but it isn't run that file)

How can I do that's purpose with editing .vimrc file?

Upvotes: 1

Views: 1097

Answers (2)

Kunal Tomer
Kunal Tomer

Reputation: 1

Plug skywind3000/asyncrun.vim

  • Open quickfix window automatically when AsyncRun is executed.

  • Set the quickfix window 6 lines height.

    let g:asyncrun_open = 6
    
  • Ring the bell to notify you job finished.

    let g:asyncrun_bell = 1
    
  • F10 to toggle quickfix window.

    nnoremap <F10> :call asyncrun#quickfix_toggle(6)<cr>
    

Upvotes: 0

Add these lines to your .vimrc

autocmd FileType c
   \ set makeprg=gcc\ -Wall\ %\ -o\ output |
   \ nnoremap  <special> <buffer> <F5> :w!<cr>:make<cr>:!./output

With this form you use :make alone for compiling.

Press F5 and then press Enter to execute the output.

Upvotes: 0

Related Questions