|
| 1 | +--- |
| 2 | +layout : post |
| 3 | +title : "The first editor off" |
| 4 | +categories : website vim atom emacs |
| 5 | +tags : blog |
| 6 | +author : Vince, Alex, Sam |
| 7 | +comments : true |
| 8 | +--- |
| 9 | + |
| 10 | +During the second week of code club we held an editor off. Like a dance off or |
| 11 | +lip syn battle but cooler: |
| 12 | + |
| 13 | + |
| 14 | +<div class="video"> |
| 15 | + <figure> |
| 16 | + <iframe width="560" height="315" src="https://www.youtube.com/embed/HvRypx1lbR4" frameborder="0" allowfullscreen></iframe> |
| 17 | + </figure> |
| 18 | +</div> |
| 19 | + |
| 20 | +For this first battle we had 4 participants with 3 weapons of choice: |
| 21 | + |
| 22 | +- Vince: Vim |
| 23 | +- Alex: Emacs |
| 24 | +- Sam: Vim |
| 25 | + |
| 26 | +This post will briefly show/discuss what they showed: |
| 27 | + |
| 28 | +## Vince |
| 29 | + |
| 30 | +### Visual mode and using `.` |
| 31 | + |
| 32 | +The first 'trick' Vince showed was how to repeat actions using the `.` |
| 33 | + |
| 34 | +Combining this with visual mode allows you to quickly and easily make modifications across a file. |
| 35 | + |
| 36 | +### Using the jedi-vim package to change Python |
| 37 | + |
| 38 | +The second 'trick' Vince showed was using the |
| 39 | +[jedi-vim](https://github.com/davidhalter/jedi-vim) plugin to quickly get the |
| 40 | +docstring for a function: |
| 41 | + |
| 42 | +Simply hit `<leader> + d` and the docstring appears in a buffer. |
| 43 | + |
| 44 | +The second thing was `<leader> + K` which takes you directly to the source code |
| 45 | +for any given function. So Vince did this on the `random.choice` function to |
| 46 | +directly access the python source code. He then quickly modified the way that |
| 47 | +function worked so that he would always win at the simple game he programmed. |
| 48 | + |
| 49 | +Note that the `<leader>` key is just any key that you can set up in Vim, Vince |
| 50 | +has this set up as the default which is `\`. |
| 51 | + |
| 52 | + |
| 53 | +## Sam |
| 54 | + |
| 55 | +### Writing output of shell commands to current buffer |
| 56 | + |
| 57 | +First, Sam showed how it is possible to run shell commands from within VIM using `:! <commands>`. |
| 58 | +Additionally, he showed how you can write the output from these commands into the current buffer using `:.! <commands>`. |
| 59 | + |
| 60 | +Vince added that a good use of this feature could be creating or adding to a .gitignore file by writing the output of an `git status` command (the output being all the files that are not being tracked by git). |
| 61 | + |
| 62 | +### Use of macros |
| 63 | + |
| 64 | +Secondly, Sam showed how you can record macros in VIM to speed up repetitive tasks. |
| 65 | + |
| 66 | +* To start recording a macro press <kbd>q</kbd><kbd>a</kbd>, <kbd>a</kbd> can be replaced by any other key you want to bind the macro to. |
| 67 | +* Carry out the commands you wish to record; aim to navigate using keys such as <kbd>w</kbd>, <kbd>e</kbd>, and <kbd>b</kbd> (navigating by words) rather that <kbd>h</kbd>, <kbd>j</kbd>, <kbd>k</kbd>, and <kbd>;</kbd> (navigating by letters) so the macro is more general and will be robust when applied to different lines. |
| 68 | +* To finish recording your macro press <kbd>q</kbd>. |
| 69 | + |
| 70 | +* To run your macro press <kbd>@</kbd><kbd>a</kbd> (or whatever key binding you used). |
| 71 | + |
| 72 | +* To run your macro on multiple lines either: |
| 73 | + * End your macro by moving down a line (<kbd>j</kbd>) and then run the macro the for the desired number of times (e.g. <kbd>5</kbd><kbd>@</kbd><kbd>a</kbd>). |
| 74 | + * Select the lines in visual mode (<kbd>V</kbd>), and then run `:norm @a` (replacing 'a' for your key binding). |
| 75 | + |
| 76 | +Sam demonstrated this by formatting a few lines of csv format data into Python dictionary format. |
| 77 | + |
| 78 | +## Alex |
| 79 | + |
| 80 | +### Butterfly Mode |
| 81 | + |
| 82 | +This was more of a joke than anything useful by claiming that emacs is the ultimate editor and emac's |
| 83 | +butterfly mode is a reference to the following [xkcd](xkcd.com) comic. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +Launching butterfly mode by typing ```M-x butterfly RET``` (M-x = Alt + x, RET = Enter) will see characters |
| 88 | +fly on from the edges of the screen and print the sentence ```Amazing physics going on``` in the centre of the |
| 89 | +screen. |
| 90 | + |
| 91 | +### Org-Babel, Tangling and Weaving |
| 92 | + |
| 93 | +On a more serious note Alex showed us Org-Babel, a facet or emac's Org-Mode which allows you to embed source code |
| 94 | +in your documents. How is this different from other formats such as Markdown? Well this source code can be |
| 95 | +"tangled" into other files. |
| 96 | + |
| 97 | +This allows us to follow a paradaigm called |
| 98 | +[Literate Programming](https://en.wikipedia.org/wiki/Literate_programming) |
| 99 | +where instead of writing the source code to a program in a format specified by the computer, you can write the |
| 100 | +source code in a way that makes sense to humans and then use Org-Babel to compile all the files from code |
| 101 | +snippets embedded in your document. |
| 102 | + |
| 103 | +I don't feel like I'm explaining this very well so let me point you in the direction of a few such programs. |
| 104 | +Alex's [Emacs Configuration](https://raw.githubusercontent.com/alcarney/emacs.d/master/README.org) |
| 105 | +is in fact a literate program using Org-Babel. While it isn't written using Org-Babel Donald Knuth's |
| 106 | +[TeX](http://mirrors.ctan.org/systems/knuth/dist/tex/texbook.tex) is probably _the_ example of a literate program. |
0 commit comments