Vim: open a temporary buffer that displays the executable

I found the command: cwindow is very useful, and I was wondering if I could get similar functionality using the output of my compiled code. I would output:! ./ a.out to appear in the "quickfix" style buffer.

I also noticed that even after taking standard steps to prevent the message “Press Enter to continue,” it still happens at least once: make and:! ./ a.out - using: silent to suppress this forces my tmux completely close. My current workaround involves matching with lots of carriage returns, is there any other way?

+3
source share
4 answers

I found this:

" 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

" }}}

steve losh.vimrc - ., .

+2

, 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>")

:

:Runcmd ls

ls

+5

:read, .

, grep , ( VIM).

, $MYVIMRC:

noremap <leader>g :new<CR>:read ! grep -rn "

, \g, , ,

:read ! grep -rn "

, . , <Enter>, .

:bw!

, .

0
source

First open the preview window and set it to save the file automatically:

:botr pedit +:setl\ autoread /tmp/out.log

Now just run your command and send the output to a file.

:!date > /tmp/out.log 2>&1

The result of your command should appear in the preview window.

However, we still get the "Press ENTER" prompt. An easy way to avoid this is to create a display that presses Enter for us:

:nmap <Leader>r :exec '!date > /tmp/out.log 2>&1'<CR><CR><CR>

I thought it would take only two <CR>, but then I would need three.

0
source

All Articles