Skip to content

Instantly share code, notes, and snippets.

@bonanAngeLOL
Last active May 30, 2023 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonanAngeLOL/9766104610f132da3ebbcd753f845d8a to your computer and use it in GitHub Desktop.
Save bonanAngeLOL/9766104610f132da3ebbcd753f845d8a to your computer and use it in GitHub Desktop.
"Compile and run a C++ file being edited in splited section
" By BonAngeLOL
" I just wrote it some minutes ago, it should (must!) be improved.
" It also could be use to execute another language code
"
" What it does?
"
" It consists of two remaps when a file is .cpp (c++)
"
"
" First: It compiles and executes the current file and displays the output in a new splited file
" so you could save that output file with :w
autocmd filetype cpp nnoremap <F10> :w<bar>cd %:p:h<bar>let f=expand('%')<bar>let p=expand('%:p:h')<bar>let b=expand('%:r')<bar>15new<bar>execute 'read !g++ '.f.' -o '.b.' && ./'.b<CR><CR>
" Second: It compiles and executes the current file and displays the output in a :terminal section so you could
" close it more easily
autocmd filetype cpp nnoremap <F9> :w<bar>term ++shell g++ %:p -o %:p:r && %:p:r<CR>
" Third: Allows exit from terminal mode pressing ESC "<C-[>" twice
" note: It currently doesn't work when Terminal job is finished. It needs to be fixed
tnoremap <C-[><C-[> <C-w>:bd!<CR>
@bonanAngeLOL
Copy link
Author

ToDo:

  • Close :terminal window pressing q

@shavaun1
Copy link

shavaun1 commented Apr 27, 2023

Hey, how to Build/Complie/run C++ Projects?

This only works for singular file.

@exkuretrol
Copy link

exkuretrol commented May 30, 2023

Hey, how to Build/Complie/run C++ Projects?

This only works for singular file.

Instead of compiling with g++, you can use a Makefile instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment