1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Add Redir command to capture command output easily

This commit is contained in:
jdhao 2021-08-13 01:17:57 +08:00
parent 37e9487076
commit 70d7f3aea5
2 changed files with 11 additions and 0 deletions

View File

@ -168,3 +168,12 @@ function! utils#GetGitBranch()
return l:res
endif
endfunction
" Redirect command output to a register for later processing.
" Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 .
function! utils#CaptureCommandOutput(command) abort
echomsg "command is" a:command
redir @m
execute a:command
redir END
endfunction

2
plugin/command.vim Normal file
View File

@ -0,0 +1,2 @@
" Capture output from a command to register @m, to paste, press "mp
command! -nargs=1 -complete=command Redir call utils#CaptureCommandOutput(<q-args>)