I'm attempting to utilise vim as a complex javascript sandbox editor.
The end goal is to have a left window with my code, and a right window with dynamically updating output from the node.js executable.
I'm currently utilising:
map <Leader>r :silent :w !node -p > /tmp/jsconsole<cr>
silent !cat '' > /tmp/jsconsole
botright vnew
e /tmp/jsconsole
set buftype=nofile
set bufhidden=hide
set nobuflisted
setlocal noswapfile
" set nomodifiable " maybe later once i can figure out how to lock/unlock
wincmd h
set buftype=nofile
set bufhidden=hide
set nobuflisted
setlocal noswapfile
autocmd QuitPre * :qa
set autoread
This works, kind of. I find that vim's autoread
function is unreliable.
Ideally, I would be able to run a left buffer's contents without saving the file through node -p
via stdin, read stdout and stderr into the right hand side buffer, which would not be editable.
I'm aware there are a few ways to do this, but lack the knowledge to glue it together.
- Reading the output to a register and showing that register in a chosen buffer
- Utilising r!
- Utilising quickfix or :make
How can I pass a buffers contents, through stdin to node -p
, capture stdout and stderr and pass them to a different buffer?