最近在使用vim时,如果账号为root时,颜色的显示是一样的;而账号为kavin(uid=500),会根据文件内容来显示不同的颜色的;因为自己比较喜欢vim的这个根据内容显示不同颜色的功能,而且对眼睛也有好处。所以自己去查找了下原因。
1、确认了下vim的配置文档,看看是否对root有特殊设置
- [root@localhost etc]# diff vimrc virc --vi有两个配置文档,先比对下连个文件是否有区别
- [root@localhost etc]# cat vimrc
- if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
- set fileencodings=utf-8,latin1
- endif
- set nocompatible " Use Vim defaults (much better!)
- set bs=indent,eol,start " allow backspacing over everything in insert mode
- "set ai " always set autoindenting on
- "set backup " keep a backup file
- set viminfo='20,\"50 " read/write a .viminfo file, don't store more
- " than 50 lines of registers
- set history=50 " keep 50 lines of command line history
- set ruler " show the cursor position all the time
- " Only do this part when compiled with support for autocommands
- if has("autocmd")
- augroup redhat
- " In text files, always limit the width of text to 78 characters
- autocmd BufRead *.txt set tw=78
- " When editing a file, always jump to the last cursor position
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line ("'\"") <= line("$") |
- \ exe "normal! g'\"" |
- \ endif
- augroup END
- endif
- if has("cscope") && filereadable("/usr/bin/cscope")
- set csprg=/usr/bin/cscope
- set csto=0
- set cst
- set nocsverb
- " add any database in current directory
- if filereadable("cscope.out")
- cs add cscope.out
- " else add database pointed to by environment
- elseif $CSCOPE_DB != ""
- cs add $CSCOPE_DB
- endif
- set csverb
- endif
- " Switch syntax highlighting on, when the terminal has colors
- " Also switch on highlighting the last used search pattern.
- if &t_Co > 2 || has("gui_running")
- syntax on
- set hlsearch
- endif
- if &term=="xterm"
- set t_Co=8
- set t_Sb=dm
- set t_Sf=dm
- endif
- [root@localhost etc]#
从上面看发现还是没有区别,应该不是vim配置文档的问题。
2、根据linux的引导顺序逐层查找原因,终于在/etc/profile.d/vim.sh文件里面被我找到了原因,以下为该文档未修改的内容:
- [root@localhost etc]# vi /etc/profile.d/vim.sh
- if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
- [ -x /usr/bin/id ] || return
- tmpid=$(/usr/bin/id -u)
- [ "$tmpid" = "" ] && tmpid=0
- [ $tmpid -le 100 ] && return
- # for bash and zsh, only if no alias is already set
- alias vi >/dev/null 2>&1 || alias vi=vim
- fi
从vim.sh文档中可以看出,如果uid小于100的账号使用vim是都是没有根据内容显示不同颜色的功能,解决办法有两种:
①修改该账号自己的.bashrc,添加内容 alias vi='vim'即可。
②直接修改/etc/vim.sh,将[ $tmpid -le 100 ] && return注释掉即可
第一种方法只能修改本账号,而第二种方法针对所有账号。
附上root更改前后的图片比对:
转载于:https://blog.51cto.com/yjh625/670011