Execute and view the output of your go code from vim

Here is a small script which I created while trying to make my feedback process faster. It runs the current go file using go run <current filename> and appends its output as a bunch of comments at the bottom of the file whenever you hit <Ctrl>d

1
2
3
4
5
6
7
8
9
10
11
function! RunHandler()
" to save the cursor position
let l:winview = winsaveview()
if &ft == "go"
:silent!$r!go run % 2>&1 | sed 's/^/\/\//g'
redraw!
echo "triggered go run " expand("%")
endif
call winrestview(l:winview)
endfunction
nnoremap <C-d> :call RunHandler()<cr>

You can use this with slight changes with other file types. Here is a screenshot:

vim screenshot

###TODO Make it overwrite the old output or insert before the previous output


I am currently working on Zammu which makes Automatic Deployment of static websites to Github Pages very easy. I would love to get your feedback on it, Use the invitation code KHAJA