【问题标题】:Displaying ► character in Vim terminal lightline status bar在 Vim 终端灯线状态栏中显示 ► 字符
【发布时间】:2015-10-03 01:14:00
【问题描述】:

我正在使用 SUSE Linux Enterprise Desktop 11 (x86_64),我在终端中使用 Vim 作为我的编辑器。我最近从https://github.com/itchyny/lightline.vim 安装了一个名为 lightline 的插件。该插件使用特殊字符使状态行看起来像这样:



栏的 > 部分实际上是 ► 字符,其颜色类似于它旁边的正方形。问题是,在我的情况下,栏看起来像这样:

尽管编码设置为 UTF-8 并且系统上安装了所有必需的字体(用于电力线的字体),但 ► 字符未正确显示。在这种情况下,终端上设置的字体是 Liberation Mono for Powerline。

我的 vimrc 中的 Lightline 设置:

set encoding=utf-8
scriptencoding utf-8

let g:lightline = {
   \ 'colorscheme': 'wombat',
   \ 'separator': {'left': "\u25B6", 'right': ''},
   \ 'subseparator': { 'left': '', 'right': ''}
   \ }

我也尝试过像这样复制 ► 字符

let g:lightline = {
       \ 'colorscheme': 'wombat',
       \ 'separator': {'left': "►", 'right': ''},
       \ 'subseparator': { 'left': '', 'right': ''}
       \ }

但它以同样的方式表现出来。

此外,在应该有空格的地方有 ^ 字符的问题。

有什么解决办法吗?

【问题讨论】:

  • 哇!不知道,谢谢!!
  • 编码通常很棘手,因为您设置的所有部分(Vim、终端等)都必须就各自的设置达成一致。你的 set encoding=utf-8 看起来很适合 Vim 部分,所以我怀疑终端设置有问题。如果您 cat 一个 UTF-8 文件会发生什么? file ~/.vimrc 对该文件的编码有何看法?
  • 好吧,这有点奇怪:S 我把 ► 放到我的 lightline 配置而不是 \u25B6 中,并将终端编码更改为 Windows-1250。在我将终端编码改回 UTF-8 后,它起作用了!我试图 cat .vimrc 并且它现在正确显示了 ►。但是 ^ 字符仍然存在。
  • @AlexKroll 我找到了解决方案!该问题在此线程stackoverflow.com/questions/7223309/… 中进行了解释。是说如果 stl 和 stlnc 具有相同的值,它们将被替换为 ^^^。当我将 * 用于 stlnc 并将空格用于 stl 时,它现在可以工作了。

标签: linux vim encoding utf-8 powerline


【解决方案1】:

以下是我的 my_configs.vim for lightline,它在我的 Fedora 26 系统中完美运行。

let g:lightline = { 
       \ 'colorscheme': 'wombat',
       \ }

let g:lightline = { 
       \ 'colorscheme': 'wombat',
       \ 'active': {
       \   'left': [ ['mode', 'paste'],
       \             ['fugitive', 'readonly', 'filename', 'modified'] ],
       \   'right': [ [ 'lineinfo' ], ['percent'] ]
       \ },
       \ 'component': {
       \   'readonly': '%{&filetype=="help"?"":&readonly?"\ue0a2":""}',
       \   'modified': '%{&filetype=="help"?"":&modified?"\ue0a0":&modifiable?"":"-"}',
       \   'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
       \ },
       \ 'component_visible_condition': {
       \   'readonly': '(&filetype!="help"&& &readonly)',
       \   'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
       \   'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
       \ },
       \ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
       \ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" }
       \ }   "" This is comment: I fotgot this line in my last post, just added

抱歉我的错误,我刚刚修复了这个配置。 如果您从 https://github.com/chrissimpkins/Hack/releases 安装了 hack 字体 并在 Fedora 26 系统中通过命令“sudo dnf install powerline-fonts”安装 powerline-fonts,您可能希望将以下配置添加到您的 /etc/fonts/local.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <alias>
    <family>Hack</family>
    <prefer>
      <family>PowerlineSymbols</family>
    </prefer>
  </alias>
</fontconfig>

【讨论】:

    【解决方案2】:

    此线程 stackoverflow.com/questions/7223309/ 中解释了该问题。它说如果stl和stlnc具有相同的值,它们将被替换为^^^。当您将 * 用于 stlnc 并将空格用于 stl 时,它会起作用。

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 2015-04-01
      • 2017-03-23
      • 2011-05-16
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      相关资源
      最近更新 更多