网上已经有一大堆关于vim的使用和配置教程,所以,对于大部分功能我就不就少了,只重点说一下安装插件
YouCompleteMe
的过程。
1. 配置文件
vim的所有配置都是在~/.vimrc文件中。默认是没有的需要自己新建:
cd ~
touch .vimrc #新建一个不存在的文件
vim .vimrc
一下为我的一些基本配置(” “为注释):
"去掉vi的一致性"
set nocompatible
"显示行号"
set number
"隐藏滚动条"
set guioptions-=r
set guioptions-=L
set guioptions-=b
"隐藏顶部标签栏"
set showtabline=0
"设置字体"
set guifont=Monaco:h13
syntax on "开启语法高亮"
let g:solarized_termcolors=256 "solarized主题设置在终端下的设置"
set background=dark "设置背景色"
set nowrap "设置不折行"
set fileformat=unix "设置以unix的格式保存文件"
set cindent "设置c样式的索引格式"
set tabstop=4 "设置table长度"
set shiftwidth=4 "同上"
set showmatch "显示匹配的括号"
set scrolloff=5 "距离顶部和底部5行"
set laststatus=2 "命令行为两行"
set fenc=utf-8 "文本编码"
set backspace=2
"set mouse=a" "启动鼠标"
set selection=exclusive
set selectmode=mouse,key
set matchtime=5
set ignorecase "忽略大小写"
set incsearch
set hlsearch "高亮搜索项"
set noexpandtab "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
set cursorline "突出显示当前行"
set cursorcolumn "突出显示当前列"
具体的含义可以参考
2. 插件
Vundle
最为强悍插件,其他插件均是基于该插件完成。安装步骤如下:
1. 安装
从github上下载安装,注意一下我们的下载到本地的路径,等下有可能会用到。
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
2.使用
在.vimrc添加Plugin命令:
"Vundle插件"
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
call vundle#end()
filetype plugin indent on
然后在vim中运行
:PluginInstall
以后只需要再添加一行
Plugin 'xxx'
并运行即可自动安装对应的插件。
YouComplete
vim的自动补全神器。
1. 安装
只需要在上面Vundle的Plugin下面添加一行命令即可:
"Vundle插件"
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
call vundle#end()
filetype plugin indent on
然后同上,运行
:PluginInstall
出现done,即安装完毕。
error修复
这个时候如果用vim打开一个文件,通常会报错:
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation
这个时候就用到前面的那个路径了:
cd ~
cd .vim/bundle/YouCompleteMe/
ls
(有install.py文件,执行下面命令)
python install.py
编译之后,一般就没啥问题了,就可以使用vim的自动功能了。
最后上一下我的.vimrc的中所有的插件:
"Vundle插件"
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Lokaltog/vim-powerline'
Plugin 'L9'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'Yggdroot/indentLine'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tell-k/vim-autopep8'
Plugin 'scrooloose/nerdcommenter'
call vundle#end()
filetype plugin indent on