Vim:打开一个显示可执行文件输出的临时缓冲区

J C*_*J C 4 vim makefile

我发现:cwindow命令非常有用,我想知道是否可以使用编译代码的输出获得类似的功能.我的输出:!./ a.out出现在"quickfix"样式缓冲区中.

我也注意到,即使采取标准步骤以防止"按Enter继续"消息,它仍然至少发生一次:make和:!./ a.out - 使用:silent来抑制这会导致我的tmux完全空白.我目前的解决方法涉及到大量回车的映射,还有另外一种方法吗?

Ben*_*enj 5

当然,您可以使用带有短函数的vim预览窗口来执行命令,在.vimrc中尝试:

fun! Runcmd(cmd)
    silent! exe "noautocmd botright pedit ".a:cmd
    noautocmd wincmd P
    set buftype=nofile
    exe "noautocmd r! ".a:cmd
    noautocmd wincmd p
endfun
com! -nargs=1 Runcmd :call Runcmd("<args>")
Run Code Online (Sandbox Code Playgroud)

然后你可以:

:Runcmd ls
Run Code Online (Sandbox Code Playgroud)

ls在预览窗口中查看结果


eps*_*lbe 3

我找到了这个:

" Shell ------------------------------------------------------------------- {{{

function! s:ExecuteInShell(command) " {{{
    let command = join(map(split(a:command), 'expand(v:val)'))
    let winnr = bufwinnr('^' . command . '$')
    silent! execute  winnr < 0 ? 'botright vnew ' . fnameescape(command) : winnr . 'wincmd w'
    setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap nonumber
    echo 'Execute ' . command . '...'
    silent! execute 'silent %!'. command
    silent! redraw
    silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
    silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>:AnsiEsc<CR>'
    silent! execute 'nnoremap <silent> <buffer> q :q<CR>'
    silent! execute 'AnsiEsc'
    echo 'Shell command ' . command . ' executed.'
endfunction " }}}
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
nnoremap <leader>! :Shell

" }}}
Run Code Online (Sandbox Code Playgroud)

在 steve losh 的 .vimrc 中 -看看我无耻地复制了什么。