Archive for July, 2012

Readable Monospace Fonts

24 Jul 2012

The default monospace fonts on the operating systems I use range from “fairly good” on Mac OS X to “awful” on Windows. This led me to search for alternatives in the hopes that I would find something that is less of a strain on my eyes while I write code. I found a surprising number of good typefaces out there, many of which are even free. I eventually settled on two, depending on what platform I am using.

Read the rest of this entry »

Better Visual Searching in Vim

12 Jul 2012

If you press * in the Vim editor it will search for the next place where the word the cursor is over appears. The # key does the same thing, but searches backwards instead. Unfortunately, this only works for one word at a time. But if you add some code to ~/.vimrc then you can extend those functions to work with whatever you have selected when you are in visual mode.

" Search for selected text, forwards or backwards
vnoremap <silent> * :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy/<C-R><C-R>=substitute(
  \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy?<C-R><C-R>=substitute(
  \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>

After adding this, select some text in visual mode (press v and move the cursor around) and search for what you have selected with * or #.

Reverting a Range of Git Commits Separately

3 Jul 2012

All kinds of articles on the Internet tell you how to revert a range of git commits in one massive, squashed-together revert commit. But to split them up into separate revert commits you have to pass a list of commits to git revert, and that list has to go in reverse order to avoid conflicts.

git rev-list --reverse ${last_good_commit}.. | xargs git revert