gpt4 book ai didi

c++ - 用于使用 g++ 编译的 .vimrc 脚本

转载 作者:行者123 更新时间:2023-11-28 05:58:01 24 4
gpt4 key购买 nike

我想在我的 .vimrc 中编写一个简短的脚本,以在 vim 中使用 g++ 编译 .cpp 文件,并在新的垂直缓冲区中打开错误/输出到我的实际文件,如下所示:

  1. 创建一个 vim 命令“:set vimcompiling”,它会引发以下步骤
  2. 保存文件:“:w
  3. 编译它:“:make ./name”(不离开 vim!)
  4. 在新缓冲区中打开文件:如果有错误::vert copen nelse:新的垂直缓冲区
  5. 中执行文件
  6. 将这些步骤 (2-4) 映射到“F5”,这样我就可以随时执行步骤 2-4 进行编译

谁能给我一些关于如何编写这样的脚本的提示?

最佳答案

BuildToolsWrappers已经内置并绑定(bind)到 F5。

正在执行 :make %<简单。然而,检测是否打开 quickfix 窗口的错误更加棘手。顺便说一句,我使用以下内容

" 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

关于c++ - 用于使用 g++ 编译的 .vimrc 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33801506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com