如何在Vim中设置默认字体大小?

tuwxkamq  于 2022-11-11  发布在  其他
关注(0)|答案(8)|浏览(491)

我正在尝试用VIM配置我的GUI的默认设置。我已经在网上做了研究,但是我找到并尝试的所有解决方案都不起作用。
以下是我尝试的一些操作(在.vimrc文件中):

set guifont = Monaco:h20
set guifont=Monospace 20

其实我不在乎摩纳哥的字体。

643ylb08

643ylb081#

对于第一个命令,删除空格。空格对于set命令很重要。

set guifont=Monaco:h20

对于第二个,它应该是(h指定高度)

set guifont=Monospace:h20

我对字体设置的建议是do(如果你的版本支持的话)

set guifont=*

这将弹出一个菜单,允许您选择字体。选择字体后,键入

set guifont?

显示当前guifont的设置。然后将该行复制到vimrc或gvimrc中。如果字体中有空格,则添加\来转义空格。

set guifont=Monospace\ 20
o2rvlv0m

o2rvlv0m2#

12之前尝试一个\<Space>,如下所示:

:set guifont=Monospace\ 12
8fq7wneg

8fq7wneg3#

我跨越了同样的问题,我把下面的代码放在文件夹~/.gvimrc中,它工作了。

set guifont=Monaco:h20
p5fdfcr1

p5fdfcr14#

将Regular添加到语法中并使用gfn
设置gfn=等宽\常规:h13

acruukt9

acruukt95#

其他答案是你所问的,但如果它对其他人有用,这里是如何从屏幕DPI有条件地设置字体(仅限Windows):

set guifont=default
if has('windows')
    "get dpi, strip out utf-16 garbage and new lines
    "system() converts 0x00 to 0x01 for 'platform independence'
    "should return something like 'PixelsPerXLogicalInch=192'
    "get the part from the = to the end of the line (eg '=192') and strip
    "the first character
    "and convert to a number
    let dpi = str2nr(strpart(matchstr(substitute(
        \system('wmic desktopmonitor get PixelsPerXLogicalInch /value'),
        \'\%x01\|\%x0a\|\%x0a\|\%xff\|\%xfe', '', 'g'),
        \'=.*$'), 1))
    if dpi > 100
        set guifont=high_dpi_font
    endif
endif
ijnw1ujt

ijnw1ujt6#

您可能会发现我制作的这个插件非常有用,它可以简化guifont的设置:https://github.com/awvalenti/vim-simple-guifont。您的vimrc是这样的,它处理所有操作系统特定的内容:

silent! call simple_guifont#Set(
  ['Cascadia Code PL', 'JetBrains Mono', 'Hack'], 'Consolas', 14)
2exbekwf

2exbekwf7#

设置guifont=Lucida\控制台:h10

epggiuax

epggiuax8#

在Ubuntu 22中,对于gvim,将“Ubuntu Mono”字体大小设置为11将在.vimrc中显示为:
set guifont=Ubuntu\ Mono\ 11

相关问题