Tip #632: Setting the font in the GUI
tip karma |
Rating 407/190, Viewed by 26524
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
January 7, 2004 11:53 |
|
complexity: |
|
basic |
author: |
|
Tony Mechelynck |
|
as of Vim: |
|
6.0 |
This tip concerns the setting of the 'guifont' option. It is assumed that 'guifontset" and 'guifontwide' will, if available, be left empty or set to a non-conflicting value. Of course, this apples only to the GUI, since the font for 'console' vim is determined by the particular terminal or terminal emulator being used.
Background
----------
1. As of this writing (January 2004) there are 3 different possible formats for the 'guifont' option, namely GTK+2, other-X11 and other. Each version of the GUI accepts only one of them.
2. Some versions allow selecting the font by means of a menu, using
:set guifont=*
However, the result is usually too restrictive.
3. Most versions allow setting an option by editing the current value, using
:set guifont=<Tab> (if 'nocompatible'), or
:set guifont=<Ctrl-E> (if 'compatible')
The current value appears, with escaping backslashes if and where needed. Change what you want to change, write it down so you can later enter it in your vimrc if you find out that you like it, then press <Enter> to accept the new result.
How to proceed
--------------
The default value for 'guifont' is the null string. However, a default or system vimrc may already have set some value. If what you see is "almost" what you want, use method 3 above. If the current value is empty, you will have to proceed in some other way. In that case, press <Esc> to leave command-line mode.
If the current value is empty, or if the current font has neither the shape nor the size that you want, try method 2 above. If it doesn't work, copy the code snippet found at the end of this tip into your vimrc and start from there, changing one thing at a time until you're satisfied.
If your version of vim allows selecting fonts via a menu, I recommend (for X11 without GTK+2) keeping only what is required to have a working font and replacing the rest (including, most especially, the last parameter, which is the encoding) by dash-separated asterisks; or (for other systems) keeping the font name and size and removing the rest (or, for non-X11, setting the encoding to cDEFAULT). See the examples below.
Now here is a snippet of code, applicable (I hope) to all versions of gvim. The only reason I haven't tested them all is I don't have them all. Start with that, change the "set" statements as needed, and put it in your vimrc.
if has("gui_running")
if has("gui_gtk2")
set guifont=Courier\ New\ 11
elseif has("x11")
set guifont=-*-courier-medium-r-normal-*-*-180-*-*-m-*-*
else
set guifont=Courier_New:h11:cDEFAULT
endif
endif
Happy Vimming!
Tony.
<< Disabling IME input in Windows |
spell check of word below cursor >>
Additional Notes
[email protected],
June 13, 2004 16:11
|
Apparently there is yet another incompatible format for 'guifont', used by the unofficial Kvim project. I don't yet know exactly what it looks like, so until I know better, please replace the above snippet by the following:
if has("gui_running")
if has("gui_gtk2")
set guifont=Courier\ New\ 11
elseif has("gui_kde")
echoerr "Sorry, please look into your kvim documentation"
elseif has("x11")
set guifont=-*-courier-medium-r-normal-*-*-180-*-*-m-*-*
else
set guifont=Courier_New:h11:cDEFAULT
endif
endif
Happy Vimming!
Tony.
|
[email protected],
July 13, 2004 16:04
|
Thanks to Dan Sharp for the following info:
For kvim [i.e. when has("gui_kde") is TRUE], there are several positional parameters separated by slashes. Internal spaces must, as always, be backslash-escaped. So in that case one may use something like
set guifont=Courier\ New/11
or
set guifont=Courier\ New/11/-1/5/50/0/0/0/1/0
The parameters here are in the following order:
font family (in this example, "Courier New")
point size (default = 10)
pixel size (-1 = default)
style hint (what to do if requested family can't be found; 5 = AnyStyle = default)
weight (50 = normal, 25 = light, 63 = semibold, 75 = bold, 87 = black)
italic (0 = no)
underline (0 = no)
strikeout (0 = no)
fixedPitch (1 = yes)
raw (0 = no)
I recommend defaulting them all except the font family and possibly the point size.
Regards,
Tony
|
imsaar at yahoo dot com,
May 2, 2005 11:27
|
If you are like me and using vim on windows and like your font to be bold (use :b) at the end.
set guifont=courier_new:h11:b
|
[email protected],
June 19, 2005 7:42
|
Again just a little "sugar" info. If you are windows, and working on a 1024x768 desktop like me, you may find Courier-New:h11 a little too big for your comfort (unless your vision doen't allow you to see smaller text)!
I use:-
: set guifont=Lucida_Consule:h8:cDEFAULT
which gives me the same size (nearly) as that of a notepad fitting as much text.
cheers.
|
[email protected],
July 5, 2005 9:03
|
I use set guifont=ProggyCleanTTSZBP:h12:cDEFAULT
It's a very good font (http://www.proggyfonts.com/)
|
agaber @ REMOVE wizart.com,
May 23, 2006 8:37
|
I tried using the Cyberbit fonts to see Unicode characters in my files, but in version 7.0 it's no longer a valid font choice. Anyone knows a monospaced, fully Unicode (i.e. all "live" languages) compliant font that I can use?
|
[email protected],
October 30, 2006 3:28
|
I have a problem with ProggyCleanTT, and it's this ; the font has no bold face.
The problem with that is that when Windows is asked to render it bold, it will synthesize a bold face by "smearing" the font one pixel to the right. This makes the boldface of ProggyCleanTT one pixel wider than the normal face.
Some applications get this right and still render the text in a rigid matrix with each character in the correct position. Other applications (notably those using the native Win32 GDI string rendering routines) render the text by drawing each character at the offset left by the previous one. This means that text applications that use boldface as part of their "prettification" of source code can seriously screw up the major reason to use a monospaced font, which is the consistent spacing of characters from line to line.
For what it's worth, GVIM appears to fall into the former category and renders ProggyCleanTT Bold at the same width as the normal face. Hoorah.
My habit is still to use Bitstream Vera Sans Mono at 8 points, since this just works properly in every text editor I use, and is nearly as good as ProggyClean.
|
[email protected],
October 30, 2006 3:35
|
Oh wow...
My last comment lead to a little googling around... and...
http://www.donationcoder.com/Software/Jibz/Dina/index.html
This guy has taken Proggy and tweaked it, added the extra faces it lacks, and provided three point sizes.
I think I shall be trying this one out in my editors for a while.
|
|