Vim 电力线奇怪的不明字符 NORMAL  unix  100%   1:1

Vim Powerline weird unidentified Characters NORMAL  unix  100%   1:1

这是我正在使用的vim版本

vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31)
Included patches: 1-2269
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       +tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     +perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          +ruby              +wildmenu
+cursorbind        +lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      +sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        +mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary
+extra_search      +mouse_sgr         -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-iU6mZD/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lcanberra -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.30/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.7 -lm

这是我的 vimrc


.vimrc

set nocompatible
set incsearch
set hlsearch
set number relativenumber
set encoding=utf-8
set noswapfile
set smartindent
set undodir=~/.vim/undodir
set undofile

let mapleader = " "

syntax enable
filetype plugin indent on
set path+=**
set wildmenu

let $RTP=split(&runtimepath,',')[0]
let $RC="$HOME/.vimrc"


" Ctrl-[ for finding definition
command! MakeTags !ctags -R .

augroup numbertoggle
autocmd!
  autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
  autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
augroup END
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')

" Declare the list of plugins.
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'junegunn/seoul256.vim'
Plug 'preservim/nerdtree'
Plug 'ap/vim-css-color'
Plug 'ajmwagar/vim-deus'
Plug 'dbeniamine/cheat.sh-vim'
Plug 'valloric/youcompleteme'
Plug 'powerline/powerline' , {'rtp': 'powerline/bindings/vim/'}

" List ends here. Plugins become visible to Vim after this call.
call plug#end()

set guifont=Source\ Code\ Pro\ for\ Powerline
set background=dark    " Setting dark mode
colorscheme deus

我想修复此错误,以便显示正确的字符 我使用的是 vim 而不是 gvim 我尝试添加字体,但没有成功。 我做错了什么?

此答案适用于希望仅在 windows 终端的 vim 中安装 powerline 的所有人(使用 wsl Ubuntu 20.04)。花了我不少时间。

我遇到这个问题的原因是 windows 终端字体中缺少字形。我尝试根据文档 (https://powerline.readthedocs.io/en/latest/installation/linux.html#fontconfig) as @romainl suggested but that didn't work. Furthermore I tried to install all powerline fonts from the github(https://github.com/powerline/fonts) 安装电力线字体,我 运行 两个安装脚本。一个根据这个 blog() 在 powershell 控制台中用于 windows,另一个根据文档在 Ubuntu WSL 机器上用于 Linux。也没用。 然后我偶然发现了 Microsoft(https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup), where the person installed a theming framework oh-my-posh. However, I neither wanted to install a theming framework nor a special version of git. Furthermore I only wanted to install powerline in vim not in my whole console. This was the moment when I asked myself: did I miss something? And indeed I did catch a little detail. The answer was to install a the Cascadia Mono PL font (https://github.com/microsoft/cascadia-code/releases) 的博客 post,其中包含丢失的字形。只需下载 zip 文件并双击字体即可。此外,我必须在 windows 终端的 setting.json 中设置字体(可以在终端中按 (CTRL + ,) 打开)。您的设置应如下所示:

{
  "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
  "hidden": false,
  "name": "Ubuntu-20.04",
  "fontFace": "Cascadia Code PL",
  "padding" : "0, 0, 0, 0",
  "source": "Windows.Terminal.Wsl"
},

现在先决条件已经处理完毕,我可以谈谈您需要在 .vimrc 中设置的正确设置,以便在 vim 中使用电力线。首先你应该使用一个插件管理器我会推荐 vim-plug(https://github.com/junegunn/vim-plug) 只是因为它被维护并且我使用它。安装 vim-plug 后,您只需在 .vimrc 的导入语句之间添加以下一行:

Plug 'powerline/powerline' , {'rtp': 'powerline/bindings/vim/'}

结论是在wsl机器上安装多少字体并不重要,也不需要在windows终端设置guifont,因为它什么都不做。这就是为什么 的文档没有真正帮助的原因,因为它遗漏了一些我需要连接点的信息。

更新: Windows 改变了它的字体命名,新 windows 终端设置页面中的新名称是 Cascadia Code PL Regular