From e54c510917c3787316e9d75ff4230edf2229e6a6 Mon Sep 17 00:00:00 2001 From: Blallo Date: Wed, 21 Jul 2021 20:43:56 +0200 Subject: [PATCH] Add redir --- config/redir.vim | 30 ++++++++++++++++++++++++++++++ vimrc | 1 + 2 files changed, 31 insertions(+) create mode 100644 config/redir.vim diff --git a/config/redir.vim b/config/redir.vim new file mode 100644 index 0000000..b9bf4f6 --- /dev/null +++ b/config/redir.vim @@ -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(, , , ) diff --git a/vimrc b/vimrc index 959d4db..2f1d9a5 100644 --- a/vimrc +++ b/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