Blog //Vim GUI Font Magic

Yesterday, Wayne tweeted this:

@erochest just dropped some vim wizardry on the @scholarslab: open system fonts, set the guifont from the settings selected in gui

I thought I should describe what I did, for several reasons. First, it’s kind of cool, in a geeky vim-lover kind of way. Second, it’s not something you do everyday, so it’s helpful to have it written down. I’m pretty surprised that I remembered it as quickly as I did.

Step 1: Select the Font Using the Standard Font Dialog

In Vim, pop open the GUI to select the font by typing in this command: :set guifont=*. It should open up the standard font dialog box for your platform.

Select the font you want to use and close the dialog.

Step 2: Add the Font to Your .vimrc file.

Now you need to make the change permanent by adding it to your .vimrc file.

Open this file using the command :e ~/.vimrc (on Linux, UNIX, and Mac) or :e ~/_vimrc (on Windows). Then add this to the bottom:

set guifont=</blockquote>

At this point, you need to insert the current value of guifont. Do this by pressing Ctrl-R (while still in insert mode) and entering this in the command bar at the bottom of the screen:


Hit enter. The name and size of the font should be appended to the set guifont line you started.

If the font name has spaces, however, you’ll need to escape those. This command should do the trick:

:s/ /\ /g</blockquote>

Unfortunately, this does a little more than you want. It also escapes the space after set. Take that out manually.

Now, the line should look something like this:

set guifont=DejaVu Sans Mono:h13</blockquote>


Some nice fonts I’ve used with Vim over the years include these:

Cite this post: Eric Rochester. “Vim GUI Font Magic”. Published August 31, 2011. Accessed on .