Vim Tips Wiki

Gtk gvim and fontconfig

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 774 Printable Monobook Previous Next

created August 20, 2004 · complexity basic · author Tye Z · version 6.0

I switched over to the GTK version of Vim (because the motif version crashes in my cygwin environment), and was distressed when I saw that my favorite 6x13 and 7x13 fonts could not be found in the font selection dialog. I found discussions on similar situations, like missing 6x13 in Gnome Terminal.

So, I spent some time reading the limited documentation on fontconfig, followed the suggestions posted here, and mangled my .fonts.config enough to give me 6x13. "Great!", I thought, "7x13 should be easy now". Nope. For the life of me, I couldn't get anything but 6x13 and 8x13.

I sympathize with folks using GTK2 applications who have very specific font preferences. Even if it's possible to get my 7x13 by messing with .fonts.config, it's WAAAAYYYYY too difficult! My understanding is that the intent is a font selection mechanism that is less platform dependant. Unfortunately, power and flexibility, the cornerstones of Unix-like OS's, suffered. So, here I was, after many hours over the course of several days of screwing around with fontconfig, feeling like I was dealing with a Microsloth app. But, I digress.

I thought I would contribute my work-around; call it a hack, if you like, but it gets me what I want. It might save the average X font user time and frustration:

If misc-fixed fonts are missing completely from your system's fontconfig, just copy the 6x13, 6x13B, and 6x13O fonts to your own directory somewhere and add that directory to your own config, and you're done. For example:

$ mkdir ~/.fonts
$ cp /usr/X11R6/lib/X11/fonts/misc/6x13{,B,O}.pcf.gz ~/.fonts
->add "<dir>~/.fonts</dir>" to ~/.fonts.conf

Then, fontconfig only has THAT font to choose from in the 'fixed' family, and you're home free. Unless you want 7x13 too.

I want 7x13 _and_ 6x13, but I can't get fontconfig to differentiate them. So, I (very easily) made my own versions of these fonts and put them in their own families:

Get the bdf sources for the fonts. I just downloaded the source package for the fonts that were installed on my system, but they should also be easy to find through an internet search.

$ mkdir ~/newfonts
$ cp path/to/source/font/7x13{,B,O}.bdf ~/newfonts

Edit each of these files, changing the family portion of FONT (i.e. the word "Fixed") and the value of FAMILY_NAME to "7x13". A quick ed script can do this to several fonts in a jiffy.

Use the bdftopcf utility to create your new fonts:

$ for font in 7x13 7x13B 7x13O ; do
> bdftopcf ./${font}.bdf -o ~/.fonts/${font}.pcf
> done

Now, as long as ~/.fonts is in your ~/.fonts.conf, 7x13 will show up in the GTK font selection dialog!

This is a one time thing for the fonts you want, and it actually makes choosing them in the app easier.


I've had to workaround this in my own way since 6.2 came out.

My workaround is to build the gtk version of vim, not the gtk2 version. Seems like that's easier than the process you describe, but does mean you have to build vim everywhere you want to use it :(

Hmmm, that's good information. I recommend that for anyone with the option. I did try it, but in my Cygwin environment, --enable-gui=gtk still gives me GTK2. :-/ Maybe there's a way to get it, but the whole font thing was just annoying me, so I went with the above.

This will also be a help for those who don't have control over other GTK2 apps, like gnome-terminal, or what-have-you.

I prefer using TTF fonts such as "Bitstream Vera Mono". They work like a charm with gtk2 vim. What you describe to me it looks like there actually is no 7x13 font. Instead you appear to use the 6x13 font and just insert a pixel extra spacing between characters? IMHO it is not a bad thing that fontconfig doesn't support such hacks...

I'm a little confused by the last note. There is indeed a 7x13 font. 6x13 and 7x13 are distinct fonts that have been present in every installation I've ever worked with. I did no pixel manipulations; that would be too much work. :-)

Tye, this has been a massive help to me. Thanks for contributing this tip. I couldn't understand why the X11 fonts were not appearing in font selection dialogue window. But now I'm starting to get it. Here's how I got my beloved "fixed" or "6x13" font to work in (g)vim-X11 running under Gnome on CentOS 6.3 (using your help)...

mkdir ~/.fonts; cd $_
cp /usr/share/X11/fonts/misc/6x13-ISO8859-1.pcf.gz .
cat <<EOF > fonts.alias
fixed -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
:set guifont=fixed

~/.fonts was already in the system fonts.conf, and the full font spec for fonts.alias comes from the generated fonts.dir. Hopefully I'll be able to use this technique for similarly gtk/fontconfig challenged apps.

Thanks !

Also on Fandom

Random Wiki