diff options
| author | jdhao <jdhao@hotmail.com> | 2021-08-13 01:17:57 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2021-08-13 01:17:57 +0800 |
| commit | 70d7f3aea5d8de71fc34a84b8b5b20c8bb01d077 (patch) | |
| tree | ceccd7a40bfbd6e59032715f5fa39ae3e84c7aa5 | |
| parent | 37e9487076d3fec7c26850ed50fbe33caae71665 (diff) | |
Add Redir command to capture command output easily
| -rw-r--r-- | autoload/utils.vim | 9 | ||||
| -rw-r--r-- | plugin/command.vim | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/autoload/utils.vim b/autoload/utils.vim index 5bbc7e8..c573a48 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -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 diff --git a/plugin/command.vim b/plugin/command.vim new file mode 100644 index 0000000..e39859b --- /dev/null +++ b/plugin/command.vim @@ -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>) |
