7

As the following post demonstrates:

How to change the default font of gVim

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.

** EDIT **

OK, now I see the documentation for setting the font by issuing the Gvim command

:help guifont

Here is what I found:

For the Win32 GUI                   *E244* *E245*
- takes these options in the font name:
    hXX - height is XX (points, can be floating-point)
    wXX - width is XX (points, can be floating-point)
    b   - bold
    i   - italic
    u   - underline
    s   - strikeout
    cXX - character set XX.  Valid charsets are: ANSI, ARABIC,
          BALTIC, CHINESEBIG5, DEFAULT, EASTEUROPE, GB2312, GREEK,
          HANGEUL, HEBREW, JOHAB, MAC, OEM, RUSSIAN, SHIFTJIS,
          SYMBOL, THAI, TURKISH, VIETNAMESE ANSI and BALTIC.
          Normally you would use "cDEFAULT".

  Use a ':' to separate the options.
- A '_' can be used in the place of a space, so you don't need to use
  backslashes to escape the spaces.
- Examples:  
    :set guifont=courier_new:h12:w5:b:cRUSSIAN
    :set guifont=Andale_Mono:h7.5:w4.5

so now for example from within Gvim I can do the the following:

:set guifont=Lucida_Console:h12:cDEFAULT

and 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.

John Sonderson
  • 3,496
  • 14
  • 49
  • 68
  • 2
    I simply have the following command in my _vimrc. Does this not work for you? `set guifont=Courier_New:h10:cANSI` – garyjohn Nov 02 '13 at 20:18
  • You must have that in your _gvimrc file though, correct, not in the _vimrc? – John Sonderson Nov 03 '13 at 13:53
  • 1
    No, I do not have a _gvimrc file. That command worked when I put it in there, and it appears to still be working, but I will check my Windows system Monday again to be sure. – garyjohn Nov 03 '13 at 18:42
  • Thanks. Can you please tell me how come the character set section of this command does not include UTF-8 and what the difference is between specifying the character set here versus specifying it with :set encoding ? Thanks. – John Sonderson Nov 03 '13 at 23:49
  • 1
    I just checked my Vim 7.4.52 running on Windows 7. The font used by gvim does indeed follow the `guifont` setting in my ~/_vimrc. As for the character set vs. encoding question, I think Tony answered that pretty well in your thread in the vim mailing list and better than I could do. – garyjohn Nov 04 '13 at 17:43
  • Thanks. For some reason I wasn't receiving the rest of the mail from the vim mailing list, but I can see the answer here: https://groups.google.com/forum/#!searchin/vim_use/sonderson/vim_use/X6_l_kIukrI/2fqvM3aeiWwJ . I guess forums are now available under Google Groups such as : https://groups.google.com/forum/#!forum/vim_use – John Sonderson Nov 06 '13 at 17:50
  • To quote Tony's answer: 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 – John Sonderson Nov 06 '13 at 17:52
  • So basically this setting is incompatible. Probably vim should clean up this command's syntax since we already have the ":set encoding" command. – John Sonderson Nov 06 '13 at 17:53
  • I'm not following you. Is incompatible with what? The various 'guifont' settings are incompatible with each other because various window managers have incompatible methods of specifying fonts and usually have different fonts available. This is something Vim can't "fix" without coming up with Yet Another Font Specification Language. The solution that seems to work well it to use `if has("...")` in your vimrc to select 'guifont' depending on your GUI environment. I'm not sure that's what you mean by "incompatible", though. – garyjohn Nov 06 '13 at 18:35
  • OK, I was just referring to the fact that Gvim seems to offer functionality in two places rather than one for setting the character encoding. Namely, both with :set guifont=... (which has a field where besides the font, the encoding is specified as well, and a separate :set econding=... which also sets the encoding. I can't seem to figure out the difference between these two ways of setting the font. Why does vim allow the encoding to be set in two different places (i.e. using two different commands), rather than with one command? – John Sonderson Nov 12 '13 at 15:38
  • i.e., Why is gvim designed with two places where the encoding can be specified rather than one place which would make more sense to me? Thanks. – John Sonderson Nov 12 '13 at 15:39
  • 1
    Where do you see encoding in the GUI Font menu? In both Windows and Linux, I see in that menu only settings for `Font`, `Font style`, `Size` and (on Windows only) `Script`. Encoding and font are different concepts. Encoding specifies the representation of characters in memory or in a file. Font specifies the look of characters on a display or page. To use gvim to view a file containing the Greek letter mu, for example, the bit pattern representing that character in the file must use some encoding that includes the character mu. To see that character on your display, you must use a font... – garyjohn Nov 12 '13 at 16:46
  • 1
    ... that includes a glyph, or an image, for that character. – garyjohn Nov 12 '13 at 16:47
  • Sorry about the late reply. Of course a character from an encoding can be rendered using different fonts. It's true, there is no encoding option in the GUI Font menu, but there is a Script option which does not make sense. What is the difference between encoding and script? And encoding for Russian encodes Russian and an encoding for Korean encodes Korean. Hence script should be redundant. This is the part I find confusing. – John Sonderson Nov 23 '13 at 17:47
  • Also, if you issue :help guifont in VIM you will see that it says cXX - character set XX. Valid charsets are: ANSI, ARABIC, ALTIC, CHINESEBIG5, DEFAULT, EASTEUROPE, ... This "character set" should correspond to what you descibe as the Script option in the GUI. – John Sonderson Nov 23 '13 at 17:50
  • I don't know what that Script setting does. It's not there in the Linux font dialog, so it's probably a Windows thing and I don't know anything about the details of Windows fonts. – garyjohn Nov 23 '13 at 21:05

3 Answers3

6

On Windows 10, I had to add this line to _vimrc in user home directory to make font setting persistent: (Default set to Consolas size 10).

set guifont=Consolas:h10

Ravi G.
  • 61
  • 1
  • 2
2

On Windows 10, I used .vimrc in my home directory and it worked. I'm not sure what the "_" (underbar) in _vimrc is supposed to represent, but traditionally Unix programs will look for a filename that starts with a "." (period) not an underbar.

So in file:

C:\Users\Brenden\.vimrc

I added one line:

set guifont=Lucida_Console:h12

And that set the font and size for me.

markspace
  • 212
  • 1
  • 3
  • 10
0

I'm using GVIM 8.0.69. It comes with vimrc_example.vim which I've edited to add following line:

set guifont=Consolas:h10.

:saveas _guirc saves config file in default home folder GVIM.

Restarted. I have my new default font.

StahlRat
  • 101
  • 4