Neovim保存代码自动异步更新cscope.out文件

此配置只支持Neovim,不支持vim,两者之间启动异步任务的jobstart函数不一样,建议使用Neovim,比vim更好用。.vimrc配置文件添加以下内容:

function! s:JobHandler(job_id, data, event) dict     
  if a:event == 'stdout'     
    let str = self.shell.' stdout: '.join(a:data)     
  elseif a:event == 'stderr'     
    let str = self.shell.' stderr: '.join(a:data)     
  else     
    let str = self.shell.' exited'     
    execute ":cs reset"     
  endif     
     
endfunction     
     
let s:callbacks = {     
\ 'on_stdout': function('s:JobHandler'),     
\ 'on_stderr': function('s:JobHandler'),     
\ 'on_exit': function('s:JobHandler')     
\ }     
     
func! UpdateCscope()     
    let job = jobstart(['bash', '-c', 'if [ -f updating.cscope ];then echo already updating ...; else echo updating ...; touch updating.cscope;cscope -Rbkq; rm updating.cscope; fi'], extend({'shell': 'shell 2'}, s:callbacks))          
endfunction

autocmd BufWritePost *.c,*.h,*.cpp,*.cc call UpdateCscope()


每次保存*.c, *.h, *.cpp, *.cc文件时,自动调用UpdateCscope函数

你可能感兴趣的:(vim,neovim)