简体   繁体   English

如何在vim中扩大空间?

[英]How to make spaces wider in vim?

I recently installed the window manager awesome, and started to use xterm. 我最近安装了窗口管理器很棒,并开始使用xterm。 While configuring the font, I came accross this webpage: https://cjshayward.com/terminal/printer.html that makes the really good point that you don't have to make the font bigger to get more easily readable code, but only to make the spaces between words wider. 在配置字体时,我来到这个网页: https ://cjshayward.com/terminal/printer.html,这非常好,你不必使字体更大,以获得更容易阅读的代码,但仅限于使单词之间的空格更宽。

How can I achieve this in vim? 我怎样才能在vim中实现这一目标?

It's not possible. 这是不可能的。 Vim uses a fixed size per character (as it's running in a terminal), and therefore the only way to change this is to change the font or font size. Vim每个字符使用固定大小(因为它在终端中运行),因此更改它的唯一方法是更改​​字体或字体大小。 To achieve a different character/letter spacing you'll need to either edit the font or choose another. 要获得不同的字符/字母间距,您需要编辑字体或选择其他字体。

The only hack I can think of is replacing every space character with its double-width companion, U+3000 ideographic space: 我能想到的唯一的黑客是用它的双宽伴侣U + 3000表意空间取代每个空间角色:

:%s/ /\=nr2char(0x3000)/g

You could use :autocmd s to undo this before, and redo after saving, but I wouldn't recommend this. 您可以使用:autocmd s之前撤消此操作,并在保存后重做,但我不建议这样做。

Unfortunately, the conceal feature only handles single-width characters so far. 不幸的是, 隐藏功能到目前为止只处理单宽度字符。 It would make for a far better workaround. 这将成为一个更好的解决方法。

@Ingo this is what I added to my .vimrc: @Ingo这是我添加到我的.vimrc:

"doubles space in insert mode    
inoremap <space> <space><space>

if !exists("autocommands_loaded")
        let autocommands_loaded = 1

        "doubles spaces when reading file
        au bufRead *.cpp        silent %s/ /  /g

        "for :w
        au bufWritePre *.cpp    silent %s/  / /g
        au bufWritePost *.cpp   silent %s/ /  /g

        "for :wq
        au quitPre *.cpp        silent %s/  / /g
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM