Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I assume you don't care if the command is executed asynchronously, since you're quitting the buffer anyway. You can use the <code>:!</code> command to run shell commands and <code>:read</code> to capture the output to a new window:</p> <pre><code>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[%#&lt;]' 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 </code></pre> <p>Then you can define an autocommand for when a buffer is unloading:</p> <pre><code>au BufUnload *.cpp s:RunShellCommand('cppcheck %') </code></pre> <p>or a somewhat more generic command which you can call at any time:</p> <pre><code>command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(&lt;q-args&gt;) </code></pre> <p>Now, to prevent closing your buffer, you have to remap <code>:wq</code> or <code>:q</code> to a function that will perform the aforementioned (plus perhaps some confirmation?), since once <code>:quit</code> is invoked, it cannot be aborted.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload