aboutsummaryrefslogtreecommitdiff
path: root/after
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2020-11-25 01:07:50 +0800
committerjdhao <jdhao@hotmail.com>2020-11-25 01:07:50 +0800
commit283356ee526c775469e52b8716c31ddba2cceee2 (patch)
tree14628fc71b720b75cfc624f94813e65947675e99 /after
parent9a7ac4c9d191117aa86808de8c056338bca1dc09 (diff)
Initial support for C++
Diffstat (limited to 'after')
-rw-r--r--after/ftplugin/cpp.vim31
1 files changed, 30 insertions, 1 deletions
diff --git a/after/ftplugin/cpp.vim b/after/ftplugin/cpp.vim
index 4fe80ab..4dd59bc 100644
--- a/after/ftplugin/cpp.vim
+++ b/after/ftplugin/cpp.vim
@@ -1 +1,30 @@
-nnoremap <F9> :<C-U>w <CR> :!g++ -Wall -std=c++11 % -o %<&&./%<<CR>
+nnoremap <silent> <buffer> <F9> :call <SID>compile_run_cpp()<CR>
+
+function! s:compile_run_cpp() abort
+ let src_path = expand('%:p:~')
+ let src_noext = expand('%:p:~:r')
+ " The building flags
+ let _flag = '-Wall -Wextra -std=c++11 -O2'
+
+ if executable('clang++')
+ let prog = 'clang++'
+ elseif executable('g++')
+ let prog = 'g++'
+ else
+ echoerr 'No C++ compiler found on the system!'
+ endif
+ call s:create_term_buf('h', 20)
+ execute printf('term %s %s %s -o %s && %s', prog, _flag, src_path, src_noext, src_noext)
+ startinsert
+endfunction
+
+function s:create_term_buf(_type, size) abort
+ set splitbelow
+ set splitright
+ if a:_type ==# 'v'
+ vnew
+ else
+ new
+ endif
+ execute 'resize ' . a:size
+endfunction