windows 在 .vimrc 文件中设置 gvim 字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3316244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set gvim font in .vimrc file
提问by Yongwei Xing
I am using gVim 7.2 on 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:
我在 Windows 7 上使用 gVim 7.2。我可以从菜单中将 gui 字体设置为 Consolas 10(字体大小)。我正在尝试在.vimrc
文件中设置它,如下所示:
set guifont=Consolas\ 10
But it doesn't work. Does anyone know how to set this?
但它不起作用。有谁知道这个怎么设置?
回答by Morten Siebuhr
I use the following (Uses Consolas size 11 on Windows, Menlo Regular size 14 on Mac OS X and Inconsolata size 12 everywhere else):
我使用以下(在 Windows 上使用尺寸为 11 的 Consolas,在 Mac OS X 上使用尺寸为 14 的 Menlo 常规尺寸,在其他地方使用尺寸为 12 的 Inconsolata):
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.
编辑:当你在做的时候,你可以看看 Coding Horror 的编程字体博客文章。
Edit2: Added MacVim.
编辑 2:添加了 MacVim。
回答by Greg Sexton
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.
这应该向您显示 Vim 已将此选项设置为的字符串。你需要逃避任何空间。
回答by Dummy00001
I am trying to set this in .vimrc file like below
我正在尝试在 .vimrc 文件中设置它,如下所示
For GUI specific settings use the .gvimrc
instead of .vimrc
, which on Windows is either $HOME\_gvimrc
or $VIM\_gvimrc
.
对于 GUI 特定设置,请使用.gvimrc
代替.vimrc
,在 Windows 上为$HOME\_gvimrc
或$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
.)
检查:help .gvimrc
详细信息。本质上,VIM 在启动时读取.vimrc
. 之后,如果 GUI 被激活,它还会读取.gvimrc
. IOW,所有 VIM 常规设置都应保存.vimrc
在.gvimrc
. (但如果您不使用控制台 VIM,那么您可以简单地忘记.vimrc
.)
set guifont=Consolas\ 10
设置 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
.
语法错误。在:set guifont=*
您始终可以使用:set guifont?
. VIM Windows 语法是:set guifont=Consolas:h10
. 我没有看到确切的规范,尽管在:help win32-faq
.
回答by qqx
- Start a graphical vim session.
- Do
:e $MYGVIMRC
Enter - Use the graphical font selection dialog to select a font.
- Type
:set guifont=
TabEnter. - Type Goto start a new line at the end of the file.
- Type Ctrl+Rfollowed by :.
- 启动图形 vim 会话。
- 做
:e $MYGVIMRC
Enter - 使用图形字体选择对话框来选择字体。
- 键入
:set guifont=
TabEnter。 - 键入Go以在文件末尾开始一个新行。
- 键入Ctrl+R后跟:.
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.
步骤 6 中的命令将插入:
包含最后使用的 ex-mode 命令的特殊寄存器的内容。这将是步骤 4 中的命令,由于先前使用 GUI 对话框设置的值的制表符完成,该命令具有格式正确的字体名称。
回答by Hradayeshkumar Sharma
For Windows do the following:
对于 Windows,请执行以下操作:
- 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.
- 从“gvim.exec”的“Edit-Select Font...”菜单中记下字体名称和字体大小。
- 然后做
:e $MYGVIMRC
- 搜索“guifont”字符串并将其更改为
set guifont=<font name as noted>:h<font size>
- 保存文件并退出。
- 下次执行gvim.exec,就会看到效果。
回答by iain
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.
反斜杠字符用于忽略下一个字符;一旦添加到我的 gvimrc 中的字体名称,它就起作用了;我在一台不喜欢空格的 GNU/Linux 机器上。我怀疑最初的帖子是一个错误,因为在 Windows 机器上使用了反斜杠。
In example:
例如:
:set guifont? ## From gvim command, would give the following:
set guifont=DejaVu Sans Mono for Powerline 11
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:
因为我需要将此行添加到 gvimrc 文件以供读取:
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 11
回答by Saket
Ubuntu 14.04 LTS
Ubuntu 14.04 LTS
:/$ cd etc/vim/
:/etc/vim$ sudo gvim gvimrc
After if - endifblock, type
在if - endif块之后,键入
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.
保存文件 (:wq!)。这里“Neep”(您的选择)是字体样式,“10”是字体大小。然后再次构建字体 - 缓存。
:/etc/vim$ fc-cache -f -v
Your desired font will set to gvim.
您想要的字体将设置为 gvim。
回答by SuperManu
I had to end up doing :set guifont=Courier:h10:cANSI
我不得不最终做 :set guifont=Courier:h10:cANSI