Add redir
This commit is contained in:
parent
eadfba174e
commit
e54c510917
30
config/redir.vim
Normal file
30
config/redir.vim
Normal 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
1
vimrc
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user