1

私の要件の解決策を得るのを手伝ってくれる人はいますか?

要件は、ユーザーが vim を終了したときにcppcheck発生する必要があり、警告またはエラーが発生した場合は、ユーザーにプロンプ​​トを表示する必要があります。

前もって感謝します。

4

1 に答える 1

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 %')

または、いつでも呼び出すことができるやや一般的なコマンド:

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

ここで、バッファを閉じるのを防ぐために、前述のことを実行する関数 (およびおそらくいくつかの確認?) に:wq再マップする必要があります。:q:quit

于 2011-08-09T06:52:44.413 に答える