set gvim font in .vimrc file
I am using gVim 7.2 o开发者_开发百科n Windows 7. I can set the gui font as Consolas 10 (font size) from the menu. I am trying to set this in .vimrc
file like below:
set guifont=Consolas\ 10
But it doesn't work. Does anyone know how to set this?
I use the following (Uses Consolas size 11 on Windows, Menlo Regular size 14 on Mac OS X and Inconsolata size 12 everywhere else):
if has("gui_running")
if has("gui_gtk2")
set guifont=Inconsolata\ 12
elseif has("gui_macvim")
set guifont=Menlo\ Regular:h14
elseif has("gui_win32")
set guifont=Consolas:h11:cANSI
endif
endif
Edit: And while you're at it, you could take a look at Coding Horror's Programming Fonts blog post.
Edit²: Added MacVim.
Try setting your font from the menu and then typing
:set guifont?
This should display to you the string that Vim has set this option to. You'll need to escape any spaces.
I am trying to set this in .vimrc file like below
For GUI specific settings use the .gvimrc
instead of .vimrc
, which on Windows is either $HOME\_gvimrc
or $VIM\_gvimrc
.
Check the :help .gvimrc
for details. In essence, on start-up VIM reads the .vimrc
. After that, if GUI is activated, it also reads the .gvimrc
. IOW, all VIM general settings should be kept in .vimrc
, all GUI specific things in .gvimrc
. (But if you do no use console VIM then you can simply forget about the .vimrc
.)
set guifont=Consolas\ 10
The syntax is wrong. After :set guifont=*
you can always check the proper syntax for the font using :set guifont?
. VIM Windows syntax is :set guifont=Consolas:h10
. I do not see precise specification for that, though it is mentioned in the :help win32-faq
.
- Start a graphical vim session.
- Do
:e $MYGVIMRC
Enter - Use the graphical font selection dialog to select a font.
- Type
:set guifont=
Tab Enter. - Type G o to start a new line at the end of the file.
- Type Ctrl+R followed by :.
The command in step 6 will insert the contents of the :
special register
which contains the last ex-mode command used. Here that will be the command
from step 4, which has the properly formatted font name thanks to the tab
completion of the value previously set using the GUI dialog.
For Windows do the following:
- Note down the font name and font size from the "Edit-Select Font..." menu of "gvim.exec".
- Then do
:e $MYGVIMRC
- Search for "guifont" string and change it to
set guifont=<font name as noted>:h<font size>
- Save the file and quit.
- Next time when you execute gvim.exec, you will see the effect.
Although this is an old thread I thought that I would add a comment as I have come across it whilst trying to solve a similar issue; this might help anyone else who may find themselves here:
The backslash character is used to ignore the next character; once added to the font name in my gvimrc it worked; I am on a GNU/Linux machine which does not like spaces. I suspect that the initial post was an error due to the back slash being used on a windows machine.
In example:
:set guifont? ## From gvim command, would give the following:
set guifont=DejaVu Sans Mono for Powerline 11
Where as I needed to add this line to the gvimrc file for it to be read:
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 11
When I try:
set guifont=Consolas:h16
I get: Warning: Font "Consolas" reports bad fixed pitch metrics
and the following is work, and don't show the waring.
autocmd vimenter * GuiFont! Consolas:h16
by the way, if you want to use the mouse wheel to control the font-size, then you can add:
function! AdjustFontSize(amount)
let s:font_size = s:font_size + a:amount
:execute "GuiFont! Consolas:h" . s:font_size
endfunction
noremap <C-ScrollWheelUp> :call AdjustFontSize(1)<CR>
noremap <C-ScrollWheelDown> :call AdjustFontSize(-1)<CR>
and if you want to pick the font, you can set
set guifont=*
will bring up a font requester, where you can pick the font you want.
I had to end up doing
:set guifont=Courier:h10:cANSI
Ubuntu 14.04 LTS
:/$ cd etc/vim/
:/etc/vim$ sudo gvim gvimrc
After if - endif block, type
set guifont=Neep\ 10
save the file (:wq!). Here "Neep" (your choice) is the font style and "10" is respect size of the font. Then build the font - cache again.
:/etc/vim$ fc-cache -f -v
Your desired font will set to gvim.
精彩评论