首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于用.vimrc编译的g++脚本

用于用.vimrc编译的g++脚本
EN

Stack Overflow用户
提问于 2015-11-19 10:38:32
回答 1查看 362关注 0票数 0

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

  1. 创建一个vim命令":set vimcompiling“,该命令将引发以下步骤
  2. 保存文件:":w
  3. 编译它:":make ./name“(不离开vim!)
  4. 在新缓冲区中打开该文件:如果出现错误:“:vertical n”,否则:在新垂直缓冲区中执行该文件
  5. 将这些步骤( 2-4 )映射到"F5“,以便我可以随时执行步骤2-4。

有人能给我一些关于如何写这样的剧本的建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-19 13:57:53

BuildToolsWrappers已经内置并绑定到F5。

执行:make %<很容易。然而,检测是否打开quickfix窗口的错误要复杂得多。在BTW中,我使用以下方法

代码语言:javascript
运行
复制
" 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33801506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档