Add redir

This commit is contained in:
sfigato 2021-07-21 20:43:56 +02:00
parent eadfba174e
commit e54c510917
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
2 changed files with 31 additions and 0 deletions

30
config/redir.vim Normal file
View File

@ -0,0 +1,30 @@
function! Redir(cmd, rng, start, end)
for win in range(1, winnr('$'))
if getwinvar(win, 'scratch')
execute win . 'windo close'
endif
endfor
if a:cmd =~ '^!'
let cmd = a:cmd =~' %'
\ ? matchstr(substitute(a:cmd, ' %', ' ' . expand('%:p'), ''), '^!\zs.*')
\ : matchstr(a:cmd, '^!\zs.*')
if a:rng == 0
let output = systemlist(cmd)
else
let joined_lines = join(getline(a:start, a:end), '\n')
let cleaned_lines = substitute(shellescape(joined_lines), "'\\\\''", "\\\\'", 'g')
let output = systemlist(cmd . " <<< $" . cleaned_lines)
endif
else
redir => output
execute a:cmd
redir END
let output = split(output, "\n")
endif
vnew
let w:scratch = 1
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
call setline(1, output)
endfunction
command! -nargs=1 -complete=command -bar -range Redir silent call Redir(<q-args>, <range>, <line1>, <line2>)

1
vimrc
View File

@ -24,6 +24,7 @@ source $VIMHOME/config/language-client.vim
source $VIMHOME/config/mucomplete.vim
source $VIMHOME/config/nerdtree.vim
source $VIMHOME/config/powerline.vim
source $VIMHOME/config/redir.vim
source $VIMHOME/config/rg.vim
source $VIMHOME/config/theme.vim " this sets the colorscheme
source $VIMHOME/config/vim-go.vim