-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruncpp.vim
More file actions
66 lines (51 loc) · 1.88 KB
/
runcpp.vim
File metadata and controls
66 lines (51 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
" C++
autocmd FileType cpp noremap <silent> <C-b> :call SaveBuildAndExecuteCPP()<CR>
autocmd FileType cpp vnoremap <silent> <C-b> :<C-u>call SaveBuildAndExecuteCPP()<CR>
function! SaveBuildAndExecuteCPP()
" Save the window where you are currently
let l:currentWindow=winnr()
" SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim
" save and reload current file
silent execute "update | edit"
" build current file
silent execute "!g++ % -o tmpbuild"
let s:output_buffer_name = "CPP"
let s:output_buffer_filetype = "output"
" reuse existing buffer window if it exists otherwise create a new one
if !exists("s:buf_nr") || !bufexists(s:buf_nr)
silent execute 'botright new ' . s:output_buffer_name
let s:buf_nr = bufnr('%')
elseif bufwinnr(s:buf_nr) == -1
silent execute 'botright new'
silent execute s:buf_nr . 'buffer'
elseif bufwinnr(s:buf_nr) != bufwinnr('%')
silent execute bufwinnr(s:buf_nr) . 'wincmd w'
endif
silent execute "setlocal filetype=" . s:output_buffer_filetype
setlocal bufhidden=delete
setlocal buftype=nofile
setlocal noswapfile
setlocal nobuflisted
setlocal winfixheight
setlocal cursorline " make it easy to distinguish
setlocal nonumber
setlocal norelativenumber
setlocal showbreak=""
setlocal laststatus=0 " turns off lightline for buffer
setlocal cc=0 " disables ruler for buffer
resize 10
" clear the buffer
setlocal noreadonly
setlocal modifiable
%delete _
" add the console output
execute ".!./" . shellescape("tmpbuild", 1)
" make the buffer non modifiable
setlocal readonly
setlocal nomodifiable
:$
" Delete tmpbuild file
silent execute "!rm tmpbuild"
" Go back to the original window
exe l:currentWindow . "wincmd w"
endfunction