The Fugue Counterpoint by Hans Fugal

12Jul/090

MacVim :recover

When your battery dies while editing a new unsaved file in MacVim, and instead of going to sleep as it should your laptop rudely shuts down, when you boot up and start MacVim again you may begin to panic because it doesn't do the regular Vim recovery dance.

Fear not, all is not lost. It's there ready for recovery. Just type :recover.

13Feb/091

Why vimdiff?

I love Vim and vimdiff, but vimdiff is pitiful for doing 3-way merges. So I wonder why git's search for a merge tool prefers vimdiff over opendiff (which launches OS X's fantastic FileMerge program).

git config --global merge.tool opendiff

29Mar/080

sh.vim

Have you ever been frustrated with perfectly valid bash syntax being highlighted as incorrect in vim? Like this:


#!/bin/sh
foo=$(ls /tmp)

$() is a perfectly valid, nay preferred substitute for backticks. The problem is that vim is deciding this is pure old bourne shell instead of whatever else we'd like it to be. If you change the shebang to #!/bin/bash and re-edit the file, then the error markings go away. But maybe you're writing for the nebulous POSIX shell, not bash nor sh. Or maybe you just don't care and you don't want vim complaining that you're using bashisms even though your shebang says sh. You can set the defaults so that it reflects your system and preferences. It's all there in :help sh.vim.

18Feb/072

gvim on OS X

In spite of being the author of one of the more (in)famous vim color schemes,
desert.vim, I have been
vimming primarily in the console for quite some time now. The primary reason is
that gvim on OS X sucks.

Still, it's nice to have gvim working for various reasons. One of the more
important reasons is dragging stuff to the Vim icon on the dock.

As a follow-up to my post on unicode in the terminal, I decided to install the latest Vim.app from macvim.org and see how it handled unicode. It didn't handle it very well, but it's only a few settings away.

First, there's the issue of font. I don't like Monaco very much. I use
Anonymous for the terminal
and I think it is an excellent font. In fact, I find myself likeing Anonymous
just as much as Terminus, but it
has the added advantage of being TrueType and looking great with antialiasing.
Unfortunately, in Vim at least it looks terrible without antialiasing. So I
got the pseudo-TrueType Terminus
font
by Eric Cheng. It took
some fiddling, because of various Bad Things™ happening with Vim and OS X
dealing with a TrueType-wrapped bitmap font, but I found the following settings
work great (put them in ~/.gvimrc):

set enc=utf-8
set macatsui noanti gfn=Terminus:h12

It's not antialiased, but it is Terminus and it handles Unicode just fine (as
far as the Terminus font itself does, which is pretty good).

You can use antialiased fonts, e.g. Anonymous, with the following .gvimrc:

set enc=utf-8
set nomacatsui anti termencoding=macroman gfn=Anonymous:h10

but Bad Things™ happen when you use Unicode, so I'm sticking with the Terminus setup.

Tagged as: , , , , 2 Comments
18Feb/075

Terminal Unicode Wrangling on OS X

This is the 21st Century. It's time for Unicode. OS X does a decent job of supporting Unicode overall, but it is far from perfect. Perhaps the most noticeable is the mass confusion that is Unicode in the terminal. The problem is actually legion, and it takes a little effort to fix it. But you can fix it and you can do it today.

Start at this article on Internationalizing the Mac OS X terminal. Following the instructions there will get you 90% of the way there. You will install a new version of bash and coreutils (for ls, cd, etc.), you'll set up your locale information (actually you only need to set LANG, in my experience. I export LANG=en_US.UTF-8 in my .bashrc).

If you use OS X's default vim (/usr/bin/vim), it will Just Work. But if you have vim 7.0 from some other source, it may or may not work. In particular if you do sudo port install vim you'll probably get a broken vim. Be sure to use the multibyte variant if you install from ports.

If you use iTerm, it might work worse than before you made the changes above. But notice that it works fine if you run another bash instance, or screen. I'm not sure but I think you fix it with the LC_CTYPE hack detailed in this article. Those .inputrc lines probably won't hurt either, though I'm not sure what problem they fix. One of those two changes seems to have fixed the iTerm problem.

Speaking of screen, you probably want to add defutf8 on to your ~/.screenrc.

I'm curious if things work out of the box in $YOURFAVORITEDISTRO. I've previously mucked about with unicode so much in Debian and Ubuntu I have no recollection of what the default state of affairs is. Try the following and let me know in the comments how it worked.

echo æøÜÉ > /tmp/ƒøø
ls /tmp/ƒøø
cat /tmp/ƒ<tab>
vim /tmp/ƒøø
screen vim /tmp/ƒøø

For me, I see exactly that and exactly what you'd expect on the terminal and in vim (both in and out of screen), which has never all happened in OS X for me before. It does work over ssh on my Debian box, but as I say I've played with things there so it may or may not have worked out of the box.

12Aug/060

:set exrc

Let's say you work on more than one project, each of which has different policy
about tabs (e.g. one of the only two sane tab policies: all real tabs or all
spaces). You need vim to behave one way in project A and another way in project
B. You could use modelines, but that's a violation of DRY.

The solution is something I'd often wished for but never realized vim did. set
exrc
in your ~/.vimrc tells vim to search the current directory for a
.vimrc or .exrc file. You might need a few symlinks (automatable with a
Makefile) to reach all the subdirectories of your project tree, but this will
solve all your problems.

Tagged as: , , , No Comments
18May/061

flog

A while back I switched my blog from Blosxom to Typo. Typo is really spiffy but
I am not a fan of HTML edit boxes, so I looked for good blog posting software.
I didn't find any, and certainly none that was free, and I was really
comfortable with writing my posts using Markdown in vim, so I decided to write
my own. Thus was born flog, so named because it rhymes with blog and reflects
the true effect that my blog has upon the world.

From the README:

Run flog and edit the post template in $EDITOR. When done, save and exit
$EDITOR and your post will be submitted.

I finally got around to adding the pieces to make it robust enough for general
consumption, and so I am releasing it. You can find it at
http://hans.fugal.net/src/flog.

Flog uses the MetaWebLog API, so it should work with a variety of blog software.

Tagged as: , , , , 1 Comment