https://github.com/zhiweichen95/vimrc
1 安装powerline
如果您是使用 Ubuntu Linux 14.10 以后的版本,建议可以直接使用 universe repository 所打包好的套件自动安装:
sudo apt-get install powerline
2 把Powerline添加到Vim中
在~/.vimrc
中添加下边语句
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
set laststatus=2
之后执行命令:source ~/.vimrc
立即生效vimrc
启动vim可能会提示python那三条语句在此版本不适用,这是因为Ubuntu16+中sudo apt-get install vim安装的vim只支持Python3,像YCM、Powerline等插件都需要Python2的支持,
E319: Sorry, the command is not available in this version: python from powerline.vim import setup as powerline_setup
具体警告提示如下:
解决办法:
安装 vim-nox-py2
,命令为:
sudo apt-get install vim-nox-py2
输入完这个命令后,大部分又会报出E: Unable to locate package vim-nox-py2
的错误,具体如下图:
此时需要添加源,在/etc/apt/sources.list
文件最上面添加一下内容:
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main universe
之后,执行命令sudo apt-get update
进行源更新。
再运行安装 vim-nox-py2
命令,应该还会报出类似Depends: vim-common (= 2:7.4.1689-3ubuntu1.2) but 2:8.0.1453-1ubuntu1 is to be installed
等的警告。
需要使用:
前两个使用sudo apt-get install vim-common=2:7.4.1689-3ubuntu1.2
这样的命令进行安装,最后一个使用sudo apt-get install libperl5.22
的命令安装。
3 使用fontconfig配置Powerline 字体
-
下载最新版的Powerline符号字体
cd ~ wget https://github.com/Lokaltog/powerline/raw/develop/font/PowerlineSymbols.otf
-
将下载的字体移动到字体文件夹中
为保险起见,我们将字体文件复制到~/.local/share/fonts/
中mv PowerlineSymbols.otf ~/.local/share/fonts/
-
更新系统字体缓存
sudo fc-cache -f -v
-
下载并移动对应的字体配置文件
wget https://github.com/Lokaltog/powerline/raw/develop/font/10-powerline-symbols.conf mkdir -p ~/.config/fontconfig/fonts.conf mv 10-powerline-symbols.conf ~/.config/fontconfig/fonts.conf/
使用 Powerline
安装好 Powerline 之后,若要在 Bash Shell 中使用,只要在 ~/.bashrc 中加入以下内容:
POWERLINE_SCRIPT=/usr/share/powerline/bindings/bash/powerline.sh if [ -f $POWERLINE_SCRIPT ]; then source $POWERLINE_SCRIPT fi
附录:
如果有兴趣的读者,也可以在这个链接 fonts for Powerline 中下载更加适配powerline的字体,对于windows用户而言,直接下载zip压缩包,右键install.ps1
文件,“使用PowerShell
运行”即可。本人尝试了在XShell中是欧克的,但是在MobaXterm中会乱码,不知道咋回事,望各位读者指教。
附上效果图:
- bash
- vim
- bash