Unit Test Your Brain

As a software engineer, I spend a lot of time in a text editor (about 40 hours per week).  Recently, I’ve been learning to use the Vim editor (specifically, MacVim) and have been pleasantly surprised by the power and flexibility.  One of my larger goals in life is to engage in deliberate practice in the things I want to become very good at.  Because of my vocation, I’ve chosen Vim as one area where it seems worthy of dedicating time and effort to becoming an expert.

So you can think of deliberate practice as Unit Tests for your brain: find an invariant function that takes inputs, applies a transform to produce outputs, and then compares the outputs with an expected value.  If I were a psychologist, I would probably be able to poke a hole in this short explanation of deliberate practice, but for this initial application to Vim, I think it suffices.

What would Unit Tests for your brain look like?  Whenever you learn something new in Vim, add a line to a text file that gives you the opportunity to practice your new ability:

Using the 'surround' plugin, remove the single quotes from 'surround'.

Your text file will grow in length as you learn new abilities.  Revisit the text file and perform each of your Unit Tests on a daily basis.  The strength of your neuronal connections will improve and you will become an expert at editing in Vim.

Using 'surround', remove the _value and replace with ['value']:
  config_value

Using a macro recording, prefix the first and third words of each
line with a double dash ("--"):
  one two three four
  five six seven eight
  nine ten eleven twelve

Display the contents of the register where you recorded the macro:

Modify the above macro to use underscores instead of dashes, and
then read the macro back into the register.

etc.

This is the best solution I’ve found to the related question I posted on the Vim list.  I hope it works for you!

Update: I forgot to mention that one really neat technique I’ve picked up is the ability to quickly go to my practice file and add new tricks.  The way I do this is by using (mark-capital-letter) in Vim: go to the practice file, and type “mP”.  This adds a bookmark to the file.  Now, whenever you want to re-visit the practice file, type ‘P (single-quote-P).   Instant access!  Any capital letter can be used.


  • thank you for this valuable info
  • I understand your hard work.besides your interest....I hope your self confidence............
  • Barry
    Ok...

    Duane,

    Since reading about your "Unit Test your Brain" concept and the underlying "Deliberate Practice" theory, I have become... obsessed.

    I have started my own vim file with your exercises, including a nice macro that creates folded "answers" for me (so I can't peek :-) )... but I want *more*...

    I searched the net. I found lots of articles about Ericsson's work and people making vague conclusions or suggestions about what to do next... but nothing concrete.

    Then I found a site where you were imploring others about how to start this for vim, which seemed to be the birthplace of Unit Testing your Brain.

    So, my question is this: what else do you have? Where do we go from here? I would be happy to work with you to create a Deliberate Practice resource, provided we do it under an OSS friendly license... like CC or something like that.

    Thoughts?
  • I'd love to work on something like this. Let me send you some of my
    unit tests tonight after work and discuss!
  • Barry
    cool. It's the wrong end of the day here for me now. I'll check for your email tomorrow.
  • Barry
    I tried to do the config_value replacement with surround, but my surround-fu is not strong.
    I had this monstrosity: xysw'v/'<cr>]
    (where the cursor is on the underscore, and <cr> means press Enter)

    I could do the same with less plain vim commands. So, what am I doing wrong?</cr></cr>
  • @Barry: My method is not that much better, but it does save a
    keystroke and doesn't require Enter:

    xves'vEs]

    If anyone knows a better way, I'm always open ears.
  • Barry
    @Duane: Nice. Obviously I had a typo in my original one (got eaten somehow when entering my comment). But yours is clearly better. I particularly like the use of the two different e/E - it serves an educational purpose (highlighting the difference between how e and E work).

    However, for this particular problem, I can still do the same in 9 keys of plain vim. I'm not saying that surround isn't cool. I'm just hoping there's a faster way to solve this problem with surround.

    My nine (ok, ten) keys of vanilla vim:

    xi['<esc>ea']<esc>

    or nine with:

    xi['<crtrl+o>$']<esc></esc></crtrl+o></esc></esc>
  • Barry
    I notice this works too:

    xysw'ysW]
  • Neat, thanks!
blog comments powered by Disqus