用于使用 g++ 编译的 .vimrc 脚本
.vimrc script for compiling with g++
我想在我的 .vimrc 中编写一个简短的脚本,以在 vim 中使用 g++ 编译 .cpp 文件,并在新的垂直缓冲区中打开 errors/output 到我的实际像这样的文件:
- 创建一个 vim 命令“:set vimcompiling”,它会引发以下步骤
- 保存文件:“:w”
- 编译它:“:make ./name”(不离开vim!)
- 在新缓冲区中打开文件:
如果有错误: ":vert copen n"
else: 在新的垂直缓冲区
中执行文件
- 将这些步骤 (2-4) 映射到“F5” 这样我就可以在任何时候想编译时执行步骤 2-4
谁能给我一些关于如何编写这样的脚本的提示?
BuildToolsWrappers 已经内置并绑定到 F5。
执行:make %<
很容易。然而,检测是否打开 quickfix window 的错误更加棘手。顺便说一句,我使用以下
" 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
我想在我的 .vimrc 中编写一个简短的脚本,以在 vim 中使用 g++ 编译 .cpp 文件,并在新的垂直缓冲区中打开 errors/output 到我的实际像这样的文件:
- 创建一个 vim 命令“:set vimcompiling”,它会引发以下步骤
- 保存文件:“:w”
- 编译它:“:make ./name”(不离开vim!)
- 在新缓冲区中打开文件: 如果有错误: ":vert copen n" else: 在新的垂直缓冲区 中执行文件
- 将这些步骤 (2-4) 映射到“F5” 这样我就可以在任何时候想编译时执行步骤 2-4
谁能给我一些关于如何编写这样的脚本的提示?
BuildToolsWrappers 已经内置并绑定到 F5。
执行:make %<
很容易。然而,检测是否打开 quickfix window 的错误更加棘手。顺便说一句,我使用以下
" 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