解决vim没有颜色的办法

问题起因,在两台host上用同样的方法编译了同样的vim73包,可是运行的时候,一台host上vim有颜色,而另一台却没有颜色。于是开始侦查。

首先打开vim,输入命令 scriptnames看看vim加载了哪些脚本。

:scriptnames

输出入下

复制代码
  1: /home/users/xxx/.vimrc
2: /home/users/xxx/tools/share/vim/vim73/colors/darkblue.vim
3: /home/users/xxx/tools/share/vim/vim73/syntax/syntax.vim
4: /home/users/xxx/tools/share/vim/vim73/syntax/synload.vim
5: /home/users/xxx/tools/share/vim/vim73/syntax/syncolor.vim
6: /home/users/xxx/tools/share/vim/vim73/filetype.vim
7: /home/users/xxx/tools/share/vim/vim73/plugin/getscriptPlugin.vim
8: /home/users/xxx/tools/share/vim/vim73/plugin/gzip.vim
9: /home/users/xxx/tools/share/vim/vim73/plugin/matchparen.vim
10: /home/users/xxx/tools/share/vim/vim73/plugin/netrwPlugin.vim
11: /home/users/xxx/tools/share/vim/vim73/plugin/rrhelper.vim
12: /home/users/xxx/tools/share/vim/vim73/plugin/spellfile.vim
13: /home/users/xxx/tools/share/vim/vim73/plugin/tarPlugin.vim
14: /home/users/xxx/tools/share/vim/vim73/plugin/tohtml.vim
15: /home/users/xxx/tools/share/vim/vim73/plugin/vimballPlugin.vim
16: /home/users/xxx/tools/share/vim/vim73/plugin/zipPlugin.vim
复制代码

可见所有和语法及颜色相关的脚本都已经加载了,应该不是它们的问题。

在看.vimrc配置文件

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

从第9行开始,如果用的是xterm,那就就进行下面的颜色设置,那么如果系统用的不是xterm呢?于是赶紧查看,在shell终端输入如下命令

echo $TERM

结果如下

vt100+

果然不是xterm,怪不得没有颜色。

解决办法:打开shell配置文件,.bash_profile或.bashrc加入下面一行

TERM=xterm
export TERM

重新敲一下bash,再次运行vim,颜色来啦!兴奋!

posted on   perlman  阅读(48070)  评论(4编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2012年1月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11
点击右上角即可分享
微信分享提示