Last active
May 30, 2023 06:21
-
-
Save bonanAngeLOL/9766104610f132da3ebbcd753f845d8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of compiling with g++, you can use a Makefile instead.