我想在.vimrc中编写一个简短的脚本,用vim中的g ++编译.cpp文件,并在新的垂直缓冲区中打开错误/输出到我的实际文件,如下所示:
有人可以给我一些关于如何编写这样一个脚本的技巧吗?
答案 0 :(得分:1)
BuildToolsWrappers已内置并绑定到F5。
执行:make %<
很容易。但是,检测错误以打开quickfix窗口是比较棘手的。在BTW中我使用以下
" Function: lh#btw#build#_show_error([cop|cwin]) {{{3
function! lh#btw#build#_show_error(...) abort
let qf_position = lh#option#get('BTW_qf_position', '', 'g')
if a:0 == 1 && a:1 =~ '^\%(cw\%[window]\|copen\)$'
let open_qf = a:1
else
let open_qf = 'cwindow'
endif
" --- The following code is borrowed from LaTeXSuite
" close the quickfix window before trying to open it again, otherwise
" whether or not we end up in the quickfix window after the :cwindow
" command is not fixed.
let winnum = winnr()
cclose
" cd . is used to avoid absolutepaths in the quickfix window
cd .
exe qf_position . ' ' . open_qf
setlocal nowrap
" if we moved to a different window, then it means we had some errors.
if winnum != winnr()
" resize the window to just fit in with the number of lines.
let nl = 15 > &winfixheight ? 15 : &winfixheight
let nl = lh#option#get('BTW_QF_size', nl, 'g')
let nl = line('$') < nl ? line('$') : nl
exe nl.' wincmd _'
" Apply syntax hooks
let syn = lh#option#get('BTW_qf_syntax', '', 'gb')
if strlen(syn)
silent exe 'runtime compiler/BTW/syntax/'.syn.'.vim'
endif
call lh#btw#filters#_apply_quick_fix_hooks('syntax')
endif
if lh#option#get('BTW_GotoError', 1, 'g') == 1
else
exe origwinnum . 'wincmd w'
endif
endfunction