我在Windows 7上使用gVim 7.2。我可以在菜单中将GUI字体设置为Consolas 10(字体大小)。我试图在.vimrc
文件中设置如下:
set guifont=Consolas\ 10
但是它不起作用。有人知道如何设置吗?
我使用以下字体(在 Windows 上使用 Consolas 大小为 11,在 Mac OS X 上使用 Menlo Regular 大小为 14,在其他地方使用 Inconsolata 大小为 12):
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
编辑:顺便说一下,你可以看看Coding Horror的编程字体博客文章。
编辑²:添加了MacVim。
set guifont=Consolas:h11:cANSI
添加到~/.vimrc
文件中。 - Jasdeep Khalsa.gvimrc
中执行此操作。 - Alexei Averchenko"gui_gtk3"
。 - RuudcANSI
,以及它是否必要? - anishpatel尝试从菜单中设置字体,然后再输入
:set guifont?
这应该向您显示Vim设置的选项字符串。您需要转义任何空格。
:e $MYGVIMRC
Enter以打开配置文件。:set guifont=
TabEnter。第6步中的命令将插入特殊寄存器:
的内容,该寄存器包含最后一次使用的ex模式命令。此处的命令来自第4步,由于使用了GUI对话框的选项卡补全,因此具有正确格式的字体名称。
guifont
选项,而不是运行任何特定的命令。 - qqx对于Windows,请执行以下操作:
:e $MYGVIMRC
set guifont=<记下的字体名称>:h<字体大小>
虽然这是一个旧的帖子,但因为我在解决类似问题时遇到了它,所以我想添加一条评论;这可能会帮助其他人找到这里:
反斜线字符用于忽略下一个字符;在我的gvimrc中将其添加到字体名称后,它就起作用了;我正在使用不喜欢空格的GNU/Linux机器。我怀疑最初的帖子是由于在windows机器上使用反斜杠而出现的错误。
例如:
:set guifont? ## From gvim command, would give the following:
设置GUI字体为DejaVu Sans Mono for Powerline,大小为11。
而我需要将这行代码添加到gvimrc文件中使其被读取:
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 11
当我尝试执行以下操作:
set guifont=Consolas:h16
警告:字体“Consolas”报告固定间距度量不良
以下是解决方法,可以使警告消失。autocmd vimenter * GuiFont! Consolas:h16
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>
set guifont=*
将会弹出一个字体请求器,在那里您可以选择您想要的字体。
我最终不得不做
:set guifont=Courier:h10:cANSI
Ubuntu 14.04 LTS
:/$ cd etc/vim/
:/etc/vim$ sudo gvim gvimrc
在 if - endif 块之后,输入
set guifont=Neep\ 10
:/etc/vim$ fc-cache -f -v
您想要的字体将被设置为gvim。
Windows 11用户
在上面的示例中找到set guifont= XXX:xx:xx
进入C:\Program Files (x86)\Vim
并使用ADMIN权限
编辑_vimrc
文件,在该文件中设置guifont代码
例如
" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim
" Use the internal diff if available.
" Otherwise use the special 'diffexpr' for Windows.
set guifont=Cascadia_Mono:h14:cANSI:qDRAFT
if &diffopt !~# 'internal'
set diffexpr=MyDiff()
endif
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg1 = substitute(arg1, '!', '\!', 'g')
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg2 = substitute(arg2, '!', '\!', 'g')
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let arg3 = substitute(arg3, '!', '\!', 'g')
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
if empty(&shellxquote)
let l:shxq_sav = ''
set shellxquote&
endif
let cmd = '"' . $VIMRUNTIME . '\diff"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
let cmd = substitute(cmd, '!', '\!', 'g')
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
if exists('l:shxq_sav')
let &shellxquote=l:shxq_sav
endif
endfunction
~/_gvimrc
中,否则,如果编辑文件~/_vimrc
,插件将停止工作。例如,语法高亮功能将停止工作。 - Yuri Pozniak