导读 Vim是Vi编辑器的一个很大的改进版本,增加了很多新特性:多级撤销、语法高亮、命令行历史记录、在线帮助、拼写检查、文件名补全、块操作、脚本语言等等。
环境
  • Centos7.7 Minimal
  • vim-8.2.221
安装VIM8

需要先安装依赖包还有常用工具包:

[root@localhost ~]# yum -y install git ncurses-devel ruby ruby-devel lua lua-devel perl perl-devel python3 python3-devel python2-devel perl-ExtUtils-Embed lrzsz cmake wget gcc gcc-c++ unzip

从github仓库下载最新的vim安装包

[root@localhost ~]# git clone https://github.com/vim/vim

开始编译安装vim

[root@localhost ~]# cd vim-master/
[root@localhost vim-master]# ./configure --with-features=huge \
            --enable-rubyinterp=yes \
            --enable-luainterp=yes \
            --enable-perlinterp=yes \
            --enable-python3interp=yes \
            --enable-pythoninterp=yes \
            --with-python-config-dir=/usr/lib64/python2.7/config \
            --with-python3-config-dir=/usr/lib64/python3.6/config-3.6m-x86_64-linux-gnu \
            --enable-fontset=yes \
            --enable-cscope=yes \
            --enable-multibyte \
            --disable-gui \
            --enable-fail-if-missing \
            --prefix=/usr/local \
            --with-compiledby='Professional operations'
[root@localhost vim-master]# make VIMRUNTIMEDIR=/usr/local/share/vim/vim82 && make install
  1. --enable-fail-if-missing 表示问题会提示报错,并停止
  2. --enable-***interp=yes 表示加入***支持
  3. --with-***-config-dir=*** 表示指定配置文件路径
  4. make VIMRUNTIMEDIR=*** 表示指定VIM可执行文件的位置

执行vim查看一下版本

[root@localhost ~]# vim

如何安装vim插件?

Vim编辑器安装自己喜欢的插件之后,使用起来会方便许多。

安装插件管理器

这里安装两个工具,一个是pathogen ,还有一个就是vimogen。
Pathogen插件用来集中管理vim的插件,Vimogen配合pathogen使用的,在~/.vimogen_repos中添加插件的地址,然后运行vimogen,自动安装.vimogen_repos里面的插件,插件安装的目录是pathogen管理的目录。

先安装pathogen:

[root@localhost ~]# mkdir -p .vim/{autoload,bundle}
[root@localhost ~]# curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

在家目录创建.vimrc文件,如果有就不用创建了。在.vimrc文件里面添加如下内容:

vim ~/.vimrc

execute pathogen#infect()
syntax on
filetype plugin indent on
set hlsearch
set backspace=indent,eol,start

然后再安装vimogen:

[root@localhost ~]# git clone https://github.com/rkulla/vimogen
[root@localhost ~]# cp -p vimogen/vimogen /usr/local/bin/

创建~/.vimogen_repos文件,这里面的插件是我需要用到的。

[root@localhost ~]# vim ~/.vimogen_repos

https://github.com/ianva/vim-youdao-translater
https://github.com/scrooloose/nerdtree


运行vimogen命令,然后输入1,进行安装操作:

[root@localhost ~]# vimogen

1) INSTALL
2) UNINSTALL
3) UPDATE
4) EXIT
Enter the number of the menu option to perform: 1



配置.vimrc文件,启用刚刚安装的两个插件
[root@localhost ~]# vim .vimrc

execute pathogen#infect()
syntax on
filetype plugin indent on
set hlsearch
set backspace=indent,eol,start
"===============nerdtree=================
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
map  :NERDTreeToggle
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

"===============vim-youdao-translator=================
vnoremap   :Ydv
nnoremap   :Ydc
noremap yd :Yde
演示一下插件
nerdtree

nerdtree实现在左侧显示目录树功能,效果如下:
按ctrl+n键 来打开或关闭目录树。

可以在目录树里面创建文件或目录。在目录树激活状态下,按m,打开菜单,然后可以选择创建,删除等操作。

输入a,来创建文件或目录

加上“/”是创建目录,不加”/”创建文件。

vim-youdao-translator

目前只会用这个插件划词翻译,哈哈哈

光标移动到单词上面,然后按ctrl+t就可以翻译了,译文会在编辑器底部的命令栏显示

总结

熟练使用vim将为我们节约很多时间,而且用起来也非常顺手,可以提高我们的效率。

本文原创地址:https://www.linuxprobe.com/centos7-install-vim8.html编辑:逄增宝,审核员:逄增宝