2011-08-09 6 views

答えて

1

とにかくバッファを終了しているので、コマンドが非同期に実行されるかどうかは気にしないと仮定します。あなたは、新しいウィンドウに出力をキャプチャするシェルコマンドを実行し、:readする:!コマンドを使用することができます。

function! s:RunShellCommand(cmdline) 
    let first = 1 
    let words = [] 
    " Expand and escape cmd arguments. 
    " shellescape() should work with '\' 
    for part in split(a:cmdline) 
     if first 
      " skip the cmd. ugly, i know. 
      let first = 0 
     else 
      if part[0] =~ '\v[%#<]' 
       let part = expand(part) 
      endif 
      let part = shellescape(part, 1) 
     endif 
     call add(words, part) 
    endfor 
    let expanded_cmdline = join(words) 

    " Create the new window 
    botright new 
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap 
    call setline(1, 'Showing output from cmd: ' . expanded_cmdline) 
    call append(line('$'), substitute(getline(2), '.', '=', 'g')) 

    " This is where actual work is getting done :-) 
    silent execute '$read !'. expanded_cmdline 

    " Uncomment the line below if you want the buffer to be 
    " non-modifiable 
    " setlocal nomodifiable 
    1 
endfunction 

その後、あなたはバッファがアンロードされたときのために自動コマンドを定義することができます

au BufUnload *.cpp s:RunShellCommand('cppcheck %') 

またはAあなたはいつでも呼び出すことができますもう少し一般的なコマンド:あなたのバッファを閉じる防ぐために、今すぐ

command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) 

、あなたはを再マップする必要がありますまたは:qを実行して、:quitが呼び出されると、それを中止することはできません。

+0

makefileやコンパイル時にcppcheckを使うにはどうすればいいですか? – learner

+0

make/ccをバックグラウンドに入れて、新しいシェルを開くなどですが、それは別の問題です。 –

関連する問題