update minimax submodule
[disinclined.org.git] / _posts / 2011-02-13-testing-script-output-from-inside-vim.html
1 ---
2 layout: note
3 ---
4
5 <p>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.</p>
6 <pre class="brush: bash;">
7 G o&lt;Esc&gt; ma:r!./filename.sh&lt;Enter&gt; $ v 'a:norm 0i## &lt;Enter&gt;
8 qt 'ajdG :r!./filename.sh&lt;Enter&gt; $ v 'a:norm 0i## &lt;Enter&gt; 'acc## Test output:&lt;Enter&gt; 'aq
9
10 @t
11 </pre>
12 <br>
13 <ul>
14 <li>G - cursor to end of file</li>
15 <li>o&lt;Esc&gt; - insert a new line</li>
16 <li>ma - create a mark in registry a</li>
17 <li>:r!./filename.sh - execute <i>filename.sh</i> and print output on next line</li>
18 <li>$ - cursor to end of line</li>
19 <li>v - switch to visual mode</li>
20 <li>'a - cursor to mark a</li>
21 <li>:norm - applies the following action to each line selected</li>
22 <li>0i## &lt;Enter&gt; - cursor to the start of the line, switch to insert mode, and write "## "</li>
23 <li>qt - start recording a macro in register t</li>
24 <li>'ajdG - cursor to mark a and delete to end of file</li>
25 <li>:r!./filename.sh&lt;Enter&gt; $ - insert the output and cursor to end of file</li>
26 <li>'a:norm 0t## &lt;Enter&gt; - comment out output</li>
27 <li>'acc## Test output:&lt;Enter&gt; 'aq - cursor to mark a, adds comment, and ends the macro</li>
28 <li>@t will now test your output </li>
29 </ul>