近期申请了10台测试环境,统一安装完RHEL6.4操作系统以后,发现其中有一台机器使用vim的时候没有颜色高亮,于是就奇怪了,经过一番搜索神技之后终于解决,解决过程与方法如下:

查看vim加载的脚本

1
2
vim
:scriptnames

输入如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/etc/vimrc                                                                                                                                                                             
/usr/share/vim/vim74/syntax/syntax.vim
/usr/share/vim/vim74/syntax/synload.vim
/usr/share/vim/vim74/syntax/syncolor.vim
/usr/share/vim/vim74/filetype.vim
/usr/share/vim/vim74/ftplugin.vim
/usr/share/vim/vim74/plugin/getscriptPlugin.vim
/usr/share/vim/vim74/plugin/gzip.vim
/usr/share/vim/vim74/plugin/matchparen.vim
/usr/share/vim/vim74/plugin/netrwPlugin.vim
/usr/share/vim/vim74/plugin/rrhelper.vim
/usr/share/vim/vim74/plugin/spellfile.vim
/usr/share/vim/vim74/plugin/tarPlugin.vim
/usr/share/vim/vim74/plugin/tohtml.vim
/usr/share/vim/vim74/plugin/vimballPlugin.vim
/usr/share/vim/vim74/plugin/zipPlugin.vim

经过与其他机器对比后,发现正常。

查看.vimrc文件

1
vim ~/.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
set nocompatible        " Vim settings, not Vi settings.  must be first
set autoindent " Auto align when insert new line, for instance, when using o or O to insert new line.
set ruler " Show ruler at the bottom-right of vim window
set showcmd
set backspace=indent,eol,start " Enable delete for backspace under insert mode"
colorscheme darkblue
set number " Show line number
syntax on
if &term =~ "xterm"
if has("terminfo")
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
else
set t_Co=8
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
endif
endif

实际上我的其它几台机器都没有这个文件,这里是别人的,只为了说明下面的问题。
我们看到第九行if &term =~ "xterm"这里的意思是如果用的是xterm就进行下面的颜色设置,如果不是呢?我们可以通过如下命令查看:

1
echo $TERM

结果为:

1
vt100+

原来不是xterm,所以此时vim并没有颜色

解决办法:在.bash_profile.bashrc加入下面一行

1
2
TERM=xterm
export TERM

source一下以后再次运行vim,终于有颜色了,撒花🎉🎉🎉