在vim中,当我使用
时:make
make的输出显示在“外部”窗口中,我不喜欢这个,我使用这个地图
nnoremap <leader>m :w <bar> make<CR><CR><CR>:copen<CR>
但是,在某些情况下,make的输出是
make: Nothing to be done for `all'.
当copen有make: Nothing to be done for all.
时如何添加autoclose到copen?
答案 0 :(得分:2)
您可以通过getqflist()
检查quickfix列表的内容。然后,如果第一行与您不想看的文字不匹配,我只会有条件地打开quickfix窗口:
nnoremap <leader>m :w <bar> make<CR><CR><CR>
\:if get(get(getqflist(), 0, {}), 'text', '') !~# 'Nothing to be done' <Bar>
\ copen <Bar>
\endif<CR>
当列表为空时,通过get()
进行访问可以避免错误。
您也可以随时打开列表,然后在条件中使用:cclose
,以便更好地满足您的需求。
答案 1 :(得分:0)
我有一个帮助我很多的vim脚本:
command! -nargs=* Build call s:RunBuild()
function! s:RunBuild()
let tmpfile = tempname()
"build and surpresses build status messages to stdout
"(stdout message are not very informative and may be very very long)
"Error messages are redirected to temporary file.
let buildcmd = "make -j 2> " . tmpfile . " >/dev/null"
let fname = expand("%")
if fname != ""
" save current buffer if possible (your bad if file is read only)
write
endif
" --- run build command ---
echo "Running make ... "
let cmd_output = system(buildcmd)
"if getfsize(tmpfile) == 0
if v:shell_error == 0
cclose
execute "silent! cfile " . tmpfile
echo "Build succeded"
else
let old_efm = &efm
set efm=%f:%l:%m
execute "silent! cfile " . tmpfile
let &efm = old_efm
botright copen
endif
call delete(tmpfile)
endfunction
然后我映射F5键以在每个vim模式下进行构建
"F5 - run make (in normal mode)
:nnoremap :Build
"F5 - run make (in visual mode)
:vnoremap :Build
"F5 - run make (in insert mode)
:inoremap :Build