Save default font on Gvim on Windows 7.

404 views
Skip to first unread message

John Sonderson

unread,
Nov 2, 2013, 3:35:03 PM11/2/13
to vim...@googlegroups.com
On Windows 7 it is impossible to save the default Gvim font from the Gvim program. Closing Gvim will cause it to completely forget about all font settings, and it is not possible to set them in the _vimrc file.

Has this been fixed in Gvim 7.4 or does this bug persist? Or does anyone know of a better way to set the default font? Cause the FixedSys font sucks as it cannot display Czech characters, and I don't want to have to go to the menu to change it every time I open a file that contains Czech characters. Thanks.

Tim Chase

unread,
Nov 2, 2013, 3:47:28 PM11/2/13
to vim...@googlegroups.com, johnso...@gmail.com
On 2013-11-02 12:35, John Sonderson wrote:
> On Windows 7 it is impossible to save the default Gvim font from
> the Gvim program. Closing Gvim will cause it to completely forget
> about all font settings, and it is not possible to set them in the
> _vimrc file.

You need to either put it in your _gvimrc (which gets processed
after the GUI has started up) rather than your _vimrc (which gets
processed before the GUI has started up), or put it in an autocmd in
your _vimrc:

autocmd GUIEnter * set guifont=YourFontSettingHere

that will fire once the GUI has started.

-tim





Gary Johnson

unread,
Nov 2, 2013, 3:58:06 PM11/2/13
to vim...@googlegroups.com
That will work, but I set the font for Windows in my ~/_vimrc, not
in a ~/_gvimrc and not from an autocommand, just

set guifont=Courier_New:h10:cANSI

Regards,
Gary

Tony Mechelynck

unread,
Nov 2, 2013, 5:15:18 PM11/2/13
to vim...@googlegroups.com
Indeed, 'guifont' is one of those settings which are used only after the
GUI starts but can be set before it does, and will be remembered until
they are needed. On windows I would use ... :cDEFAULT though. :cANSI is
IMHO needlessly limited and, taking it at face value, it conflicts with
using any codepoint above U+007F, including not only non-Latin letters
but even accented letters as used in practically every language other
than English (and even in English, my Oxford's Dictionary lists some
words with accented letters like garçon, cliché, risqué, øre, and more).

The 'guifont' setting has a number of different incompatible settings.
If you only use Vim on Windows this is not of much concern to you, but
there are at least two very different formats in current use on Linux,
and there used to be one more. See
http://vim.wikia.com/wiki/Setting_the_font_in_the_GUI


Best regards,
Tony.
--
Someone did a study of the three most-often-heard phrases in New York
City. One is "Hey, taxi." Two is, "What train do I take to get to
Bloomingdale's?" And three is, "Don't worry. It's just a flesh wound."
-- David Letterman

John Joche

unread,
Nov 2, 2013, 8:45:35 PM11/2/13
to Tim Chase, vim...@googlegroups.com
Thanks for the clarification.

Is there a place where I can find the string to substitute in place
of YourFontSettingHere though? Do I need to enclose the string
in double quotes or use some other quotation mechanism? I
would like to use the "Lucida Console" font with a "Normal"
font style and a size of 14. Exactly how do I specify these?

Thanks a lot!

Tim Chase

unread,
Nov 2, 2013, 9:14:06 PM11/2/13
to vim...@googlegroups.com
On 2013-11-02 12:58, Gary Johnson wrote:
> > You need to either put it in your _gvimrc (which gets processed
> > after the GUI has started up) rather than your _vimrc (which gets
> > processed before the GUI has started up), or put it in an autocmd
> > in your _vimrc:
> >
> > autocmd GUIEnter * set guifont=YourFontSettingHere
> >
> > that will fire once the GUI has started.
>
> That will work, but I set the font for Windows in my ~/_vimrc, not
> in a ~/_gvimrc and not from an autocommand, just
>
> set guifont=Courier_New:h10:cANSI

I hadn't tested it stand-alone in the vimrc, as the OP had mentioned
that it hadn't worked for him when put there. If it's *supposed* to
work there, then it might require some different debugging.

-tim


Gary Johnson

unread,
Nov 2, 2013, 9:23:56 PM11/2/13
to vim...@googlegroups.com
On 2013-11-02, Tony Mechelynck wrote:
> On 02/11/13 20:58, Gary Johnson wrote:

> >That will work, but I set the font for Windows in my ~/_vimrc, not
> >in a ~/_gvimrc and not from an autocommand, just
> >
> > set guifont=Courier_New:h10:cANSI
> >
> >Regards,
> >Gary
> >
> Indeed, 'guifont' is one of those settings which are used only after
> the GUI starts but can be set before it does, and will be remembered
> until they are needed. On windows I would use ... :cDEFAULT though.
> :cANSI is IMHO needlessly limited and, taking it at face value, it
> conflicts with using any codepoint above U+007F, including not only
> non-Latin letters but even accented letters as used in practically
> every language other than English (and even in English, my Oxford's
> Dictionary lists some words with accented letters like gar�on,
> clich�, risqu�, �re, and more).

I chose Courier_New for my Windows font setting specifically because
it contains glyphs for some Unicode codepoints not in Fixedsys,
which I otherwise like. I just copied the cANSI part from
someplace; I don't remember where. If using cDEFAULT will make even
more codepoints available, that would be great. I'll try it when I
get to work on Monday. Thank you.

Regards,
Gary

Cesar Romani

unread,
Nov 2, 2013, 9:35:37 PM11/2/13
to vim...@googlegroups.com
On 02/11/2013 07:45 p.m., John Joche wrote:
> Thanks for the clarification.
>
> Is there a place where I can find the string to substitute in place
> of YourFontSettingHere though? Do I need to enclose the string
> in double quotes or use some other quotation mechanism? I
> would like to use the "Lucida Console" font with a "Normal"
> font style and a size of 14. Exactly how do I specify these?

set guifont=Lucida\ Console:h14:cANSI

--
Cesar

Ben Fritz

unread,
Nov 2, 2013, 10:21:51 PM11/2/13
to vim...@googlegroups.com
On Saturday, November 2, 2013 2:35:03 PM UTC-5, John Sonderson wrote:
> On Windows 7 it is impossible to save the default Gvim font from the Gvim program. Closing Gvim will cause it to completely forget about all font settings, and it is not possible to set them in the _vimrc file.
>
> Has this been fixed in Gvim 7.4 or does this bug persist? Or does anyone know of a better way to set the default font? Cause the FixedSys font sucks as it cannot display Czech characters, and I don't want to have to go to the menu to change it every time I open a file that contains Czech characters. Thanks.

Setting guifont in the _vimrc works just fine in Vim 7.4 on Windows 7. I've been using 7.4 since it came out of beta on Windows 7, and I set my font to DejaVu Sans Mono in my _vimrc.

To set the font, I always use:

:set guifont=*

This brings up a dialog for me to select the font as I like it.

Then I can :echo getfontname() to see what that turns into as a Vim option value.

John Joche

unread,
Nov 3, 2013, 8:19:06 AM11/3/13
to Tim Chase, vim...@googlegroups.com
Hi,

I can set the font from within gvim on Windows 7 with
:set guifont=Lucida\ Console

but I can't seem to find where to set the font size.
Any ideas?

Thanks.

Nikolay Pavlov

unread,
Nov 3, 2013, 8:37:17 AM11/3/13
to vim...@googlegroups.com, Tim Chase


On Nov 3, 2013 5:19 PM, "John Joche" <johnso...@gmail.com> wrote:
>
> Hi,
>
> I can set the font from within gvim on Windows 7 with
> :set guifont=Lucida\ Console
>
> but I can't seem to find where to set the font size.
> Any ideas?

:h 'guifont', search for paragraph "For the Win32 GUI".

> Thanks.
>
>
> On Sun, Nov 3, 2013 at 1:45 AM, John Joche <johnso...@gmail.com> wrote:
>>
>> Thanks for the clarification.
>>
>> Is there a place where I can find the string to substitute in place
>> of YourFontSettingHere though? Do I need to enclose the string
>> in double quotes or use some other quotation mechanism? I
>> would like to use the "Lucida Console" font with a "Normal"
>> font style and a size of 14. Exactly how do I specify these?
>>
>> Thanks a lot!
>>
>>
>> On Sat, Nov 2, 2013 at 8:47 PM, Tim Chase <v...@tim.thechases.com> wrote:
>>>
>>> On 2013-11-02 12:35, John Sonderson wrote:
>>> > On Windows 7 it is impossible to save the default Gvim font from
>>> > the Gvim program. Closing Gvim will cause it to completely forget
>>> > about all font settings, and it is not possible to set them in the
>>> > _vimrc file.
>>>
>>> You need to either put it in your _gvimrc (which gets processed
>>> after the GUI has started up) rather than your _vimrc (which gets
>>> processed before the GUI has started up), or put it in an autocmd in
>>> your _vimrc:
>>>
>>>   autocmd GUIEnter * set guifont=YourFontSettingHere
>>>
>>> that will fire once the GUI has started.
>>>
>>> -tim
>>>
>>>
>>>
>>>
>>>
>>
>

> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>  
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

John Joche

unread,
Nov 3, 2013, 8:56:35 AM11/3/13
to Tim Chase, vim...@googlegroups.com
OK. Thank you for your help...

I can put the command
set guifont=Lucida_Console:h12:cDEFAULT

inside C:\Users\JSonderson_gvimrc and this font family and font size and character set is loaded each time I start gvim.


However a question still remains, that is, how come UTF-8 is not on the list of character sets?

Isn't the character set something separate from the font anyways?

What's the difference between character set and character encoding?

How can I display the actual character set which is being used when I use the DEFAULT setting?

Thanks.

Tony Mechelynck

unread,
Nov 3, 2013, 6:27:14 PM11/3/13
to vim...@googlegroups.com
On 03/11/13 14:56, John Joche wrote:
> OK. Thank you for your help...
>
> I can put the command
>
> |set guifont=Lucida_Console:h12:cDEFAULT
> |
>
> inside /C:\Users\JSonderson_gvimrc/ and this font family and font size
> and character set is loaded each time I start gvim.
>
> ------------------------------------------------------------------------
>
> However a question still remains, that is, how come UTF-8 is not on the
> list of character sets?

tl;dr: see last paragraph above your next question

UTF-8 is one of the ways to represent Unicode in memory. Unicode is the
Universal character set, a superset of all possible character sets known
to computer software.

The following encodings can represent all Unicode codepoints ("characters"):
- UTF-8, with between 1 and 4 bytes per character (originally up to 6
bytes had been foreseen, but then it was decided that codepoints above
U+10FFFF would never be attributed). UTF-8 has the property that the 128
US-ASCII characters are represented in UTF-8 by one byte in exactly the
same way as in US-ASCII, Latin1, and most other ASCII-derived encodings.
(EBCDIC is of course a world apart).
- UTF-16, with one or two 2-byte words per character;
- UTF-32 (aka UCS-4), with one 4-byte doubleword per character;
- GB18030, with 1, 2 or 4 bytes per character but biased in favour of
Chinese (this is the current official standard encoding of the PRC).
Conversion between GB18030 and the other ones is possible but not
trivial, and requires bulky tables. The iconv utility can usually do it,
and so can Vim if built with +iconv, or with +iconv/dyn and it can find
the iconv or libiconv library.

UTF-16 and UTF-32 can be big-endian (default) or little-endian (e.g.
UTF-16le). UTF-32 even supports the rarely used 3412 and 2143 byte
orderings but I'm not sure Vim knows about it.

Vim represents internally UTF-16 and UTF-32 as UTF-8 in memory, because
a NUL codepoint is a null word in UTF-16, a null doubleword in UTF-32,
and the many other null bytes in the files would play havoc with Vim's
use of null-terminated C strings. OTOH, in UTF-8 nothing other than the
NUL codepoint U+0000 may validly include a null byte in its representation.

With some filetypes, it is possible to tell user applications which
Unicode encoding and endianness to use by adding the codepoint U+FEFF at
the very start of the file. That codepoint is usually called the BOM
(byte-order mark) but it can even identify UTF-8 which has no endianness
variants. It is supported for at least HTML and CSS; it is not
recognized (and should not be present) in executable scripts in UTF-8,
especially those where the first line starts with #! — I've been caught
by that in the past, and now I know better.

Note that when Windows people say "Unicode" they usually mean UTF-16le.
That's e.g. how one must decode the sentence "The file is not in UTF-8,
it's in Unicode" (which, taken literally, is nonsense) in the mouth of a
Microsoft engineer.

You set the 'encoding' option, preferably near the top of your vimrc, to
tell Vim how characters are to be represented in memory. The advantage
of using ":set enc=utf8" is that it allows Vim to represent in memory
any character of any charset known to computer people. OTOH, e.g. using
Latin1 as your 'encoding' value only allows to represent the 256
characters which are part of the Latin1 charset; those are also the
first 256 codepoints (U+0000 to U+00FF) of Unicode.

See also http://vim.wikia.com/wiki/Working_with_Unicode

All of the above is independent of the 'guifont' setting. Why is there
nothing relating to Unicode in the :cXX parameter of Windows 'guifont'
settings? I'm not sure. Either :cDEFAULT means Unicode, or else it's a
Windows mystery.

>
> Isn't the character set something separate from the font anyways?

Yes, it is; but each font file has glyphs for a certain set of
languages. Usually not for all Unicode codepoints which are defined,
there are an enormous lot of them.

>
> What's the difference between character set and character encoding?

Not much. In most situations they can be used as synonyms. When not
synonymous, the character set is the array of characters, and the
character encoding is the exact manner those characters are represented
(by how many bytes, and which ones) in memory, on disk, on tape, etc.
Sometimes both words are used one for the other: e.g. in HTTP or mail
headers, the Content-Type line uses "charset=" to tell the receiving
application which encoding is used in the document.

Unicode can be regarded as one abstract character set with room for more
than a million characters (originally two thousand million, but then the
number was reduced), which ATM can be represented in at least 8
different encodings if all byte-ordering variants are considered. Not
all the Unicode "slots" have already received an assignment; some are
reserved "for private use" and others have been blocked as
"noncharacters". For details, see http://www.unicode.org/ and in
particular http://www.unicode.org/charts/

>
> How can I display the actual character set which is being used when I
> use the DEFAULT setting?

You don't. The font either has a glyph for the character you're trying
to display (and you should see that glyph), or it doesn't (and you
should see some placeholder glyph instead, e.g. an empty frame or a
reverse-video question mark).

>
> Thanks.
>
>

Best regards,
Tony.
--
Love in your heart wasn't put there to stay.
Love isn't love 'til you give it away.
-- Oscar Hammerstein II

Tony Mechelynck

unread,
Nov 3, 2013, 6:49:48 PM11/3/13
to vim...@googlegroups.com
Yes, ":set gfn=*" is a good thing to use, in the GUI flavours that
support it (Win32, GTK, Motif, Mac OS and Photon, according to the
help). "GTK" here means both GTK2 and the now upstream-unsupported GTK1.

Once the font is set, you can also use

:set gfn=<Tab> (without <Enter>)

to see it displayed with backslash-escaping if and where needed. On
Windows you can usually set 'guifont' with no need for
backslash-escaping (replacing any spaces by underscores) but for
instance on GTK2, with my current settings,

:echo '«' . getfontname() . '»'

returns «Bitstream Vera Sans Mono 8», and

:verbose set gfn?

returns

guifont=Bitstream Vera Sans Mono 8
Last set from ~/.vimrc

but

:set gfn=<Tab>

completes the command to

:set gfn=Bitstream\ Vera\ Sans\ Mono\ 8|

where the | at the end represents the cursor.



Best regards,
Tony.
--
The makers may make
and the users may use,
but the fixers must fix
with but minimal clues

Reply all
Reply to author
Forward
0 new messages