<p>I’m working on an Elixir app at the moment and really enjoying it, but some of my recent dabbling in the type-safe worlds of <a href="https://elm-lang.org">Elm</a> and <a href="https://crystal-lang.org">Crystal</a> have left me desiring a bit more structure in my code. The app I’m building involves a multi-step data transformation and so I have a data structure to properly represent this process. But since Elixir is a dynamically typed language, you can’t, for example, have a non-nillable field in a struct. The Elixir/Erlang ecosystem does, however, have a type-checking syntax called <a href="https://hexdocs.pm/elixir/typespecs.html">Type Specs</a>, along with a tool, <a href="http://erlang.org/doc/man/dialyzer.html">Dialyzer</a>,...</p>
Blog Entries tagged "vim"
<p>I had a ridiculous typo in a Git commit message recently, so I decided to explore spell checking in Vim. As it turns out, it’s extremely easy.</p> <p>I only wanted it enabled for Git commit messages and markdown, so I added the following to my vimrc / init.vim:</p> <div class="highlight"><pre class="highlight viml"><code><span class="c">" Spell-check Markdown files and Git Commit Messages</span> autocmd <span class="nb">FileType</span> markdown <span class="k">setlocal</span> <span class="nb">spell</span> autocmd <span class="nb">FileType</span> gitcommit <span class="k">setlocal</span> <span class="nb">spell</span> </code></pre></div> <p>By doing this, it highlights potential misspellings in red underline. You can see a list of potential corrections by moving the cursor over the word in normal mode and...</p>
<p>Here’s a handy Vim command that I find myself searching for often. It could easily be made into a function in your vimrc.</p> <div class="highlight"><pre class="highlight viml"><code><span class="c">" 4 spaces to 2 spaces</span> %s;^\<span class="p">(</span>\s\<span class="p">+</span>\<span class="p">)</span>;\<span class="p">=</span><span class="nb">repeat</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="nb">submatch</span><span class="p">(</span><span class="m">0</span><span class="p">))</span>/<span class="m">2</span><span class="p">)</span>;<span class="k">g</span> <span class="c">" Tab to 2 spaces</span> %s<span class="sr">/\t/</span> /<span class="k">g</span> </code></pre></div>
<p>In order for testing to become part of your development workflow, it needs to become a habit. And like any habit, its biggest enemy is neglect. Too often I’ll be in a rush and not add tests to my code for a day, and that turns into a week and then a month, and suddenly I have an app where half of my codebase is untested and the other half has breaking tests. There are many things you can do to help keep this habit (hooking up a CI server immediately comes to mind), but an important one is to make running your tests as quick and easy as possible.</p> <p>One way I do this is by making my ruby tests (either Rspec or Minitest) extremely easy to run while I’m using <a href="http://www.vim.org">Vim</a> (and <a href="https://tmux.github.io">Tmux</a>). With one quick keystroke, I can run the current test file or individual test in a new Tmux pane.</p> <p></p>