Last active
October 27, 2020 14:11
-
-
Save EMPAT94/5dfe876962211b6c5c2ce4d70e5f8a71 to your computer and use it in GitHub Desktop.
Quicky run an external command (eg node) on current buffer and show output in temporary vertical split
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Add the following in your vim config | |
function! ShowNodeResult() | |
" command to run on current buffer | |
let op = system("node", bufnr()) | |
" name of output buffer | |
let win = bufwinnr("__NODE_OUTPUT__") | |
" Check if existing output buffer exists | |
if win == -1 | |
" If not exists, create a new one | |
vsplit __NODE_OUTPUT__ | |
" Do not save to disk or create backups | |
setlocal buftype=nofile | |
setlocal nobackup noswapfile nowritebackup | |
else | |
" If exists, switch to it | |
exe win . "wincmd w" | |
" Clear buffer | |
normal! ggdG | |
endif | |
" Append output | |
call append(0, split(op, '\v\n')) | |
endfunction | |
" Bind to a command | |
command! -nargs=0 Node :call ShowNodeResult() | |
" To close the window on exit | |
augroup nodeOP | |
autocmd! | |
autocmd BufLeave __NODE_OUTPUT__ bwipe | |
augroup end | |
" Inspired by : https://learnvimscriptthehardway.stevelosh.com/chapters/52.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment