centos安装vim以及设置

原文链接:http://www.xiaohuai.com/2884

Centos里的VI只默认安装了vim-minimal-7.x。所以无论是输入vi或者 vim查看文件,syntax功能都无法正常启用。因此需要用yum安装另外两个组件:vim-common-7.x和vim-enhanced- 7.x。
命令行里敲入:

1
# yum -y install vim*

即可安装vim的其他组件,就可以使用vim的语法高亮等服务了。
需要使用语法高亮,还得修改/etc/vimrc

1
# vi /etc//vimrc

然后在结尾加上

1
2
3
4
5
6
7
8
9
set syntax=on
set t_Co=256
colorscheme 256
let &termencoding=&encoding
set fileencodings=gb2312,gb18030,utf-8
set termencoding=utf-8
set encoding=prc
set backspace=2
set nu

上面的colorscheme 256,这个是配色方案,配色方案可以去http://vimcolorschemetest.googlecode.com/svn/html/index-html.html 下载,下载后的文件放在/usr/share/vim/vim72/colors/目录下。

还要记得一点,在ssh客户端的终端仿真里,要设置终端使用Xterm,同时勾选ANSI颜色。

为了让vim支持nginx语法,我们可以去http://www.vim.org/scripts/script.php?script_id=1886 网址下载nginx的语法配置文件。最新的配置文件下载地址:http://www.vim.org/scripts/download_script.php?src_id=14376,下载完后存放在/usr/share/vim/vim72/syntax/目录下,然后修改/usr/share/vim/vim72/filetype.vim在结尾加上

1
au BufRead,BufNewFile /usr/local/nginx/conf/* set ft=nginx

如果要使用vi命令替换vim命令,可以修改/etc/bashrc,在结尾加入

1
alias vi='vim'

保存退出后,重启服务器生效。

原文地址:https://www.cnblogs.com/zsmynl/p/3537151.html