This is a macro that's been very helpful for me while writing short scripts in Vim. It adds and comments out the output of your script (or any command) to the end of the current file.
G o<Esc> ma:r!./filename.sh<Enter> $ v 'a:norm 0i## <Enter> qt 'ajdG :r!./filename.sh<Enter> $ v 'a:norm 0i## <Enter> 'acc## Test output:<Enter> 'aq @t
- G - cursor to end of file
- o<Esc> - insert a new line
- ma - create a mark in registry a
- :r!./filename.sh - execute filename.sh and print output on next line
- $ - cursor to end of line
- v - switch to visual mode
- 'a - cursor to mark a
- :norm - applies the following action to each line selected
- 0i## <Enter> - cursor to the start of the line, switch to insert mode, and write "## "
- qt - start recording a macro in register t
- 'ajdG - cursor to mark a and delete to end of file
- :r!./filename.sh<Enter> $ - insert the output and cursor to end of file
- 'a:norm 0t## <Enter> - comment out output
- 'acc## Test output:<Enter> 'aq - cursor to mark a, adds comment, and ends the macro
- @t will now test your output