VIM 配置文件

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@localhost ~]# touch ~/.vimrc
[root@localhost ~]# vim ~/.vimrc

"高亮行尾的空格
"highlight ExtraWhitespace ctermbg=red guibg=red
"autocmd BufWinEnter * match ExtraWhitespace /\s\+$\| \+\ze\t\+\|\t\+\zs \+/

"高亮行尾的空格 与 TAB
autocmd BufWinEnter * match Error /\t \+\|\t\|\s\+$\|^ \+$/

"设置ds按键为去除行尾空格
map ds :%s/\s\+$//g<CR>

"设置dm按键为去除行尾的^M标记
map dm :%s/\r//g<CR>

"设置dt按键将tab转为4个空格
map dt :%s/\t/ /g<CR>

"设置dr按键将多个空行变为1个空行
map dr :g/^\s*$\n\s*$/d<CR>

"设置de按键为去清空以#开头的行
map de :%s/^#.*$//g<CR>

"高亮显示当前行
set cursorline
highlight CursorLine cterm=NONE ctermbg=lightblue

"高亮显示当前列
"set cursorcolumn
"highlight CursorColumn cterm=NONE ctermbg=lightblue

set shortmess=a "关闭显示帮助乌干达的儿童
"set cmdheight=2 "vim命令状态栏的高度 (有时行显示错乱)
set noswapfile "不生成.swp文件
set bg=dark "字体高亮
set paste "粘贴时 禁止自动缩进
set completeopt=menu "关闭草稿
set nonu "不显示行号
set ruler "右下角显示光标当前位置
set scrolloff=10 "光标到上下缓冲区边距
set nobackup "禁止生成临时文件
set nocindent "不使用C风格缩进
set noautoindent "不使用自动缩进
set shiftwidth=4 "自动缩进字符宽度
set ts=4 "tab键宽度
set expandtab "将tab符转为空格
%retab! "对于已保存的文件,将tab转换为空格
set ignorecase "搜索时 忽略大小写
syntax on "语法高亮
set hls "搜索高亮
set nocompatible "去除兼容vi
set backspace=indent,eol,start "允许使用退格键
set fileencodings=utf-8,GB18030 "打开文件 支持的字符集
silent edit ++ff=unix "将当前文件文件格式转为UNIX格式
"set list "显示所有字符
set viminfo='20,<1000 "多行复制

set mouse= "禁用鼠标
set ttymouse= "禁用鼠标

效果

^I显示的是tab符号, tab 附近的空格也会显示为红色
^M显示的是 \r 符号
$ 显示的是 \n 符号

行尾的红色是行尾空格

扩展版

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[root@CentOS ~]# cat  ~/.vimrc 
"按q快速退出
map q :q<CR>

"按w保存当前文件
map w :w<CR>

"按make执行当前文件路径的Makefile文件
map make :! clear; make clean; make<CR>

" C 函数高亮 vim /usr/share/vim/vim74/syntax/c.vim
" syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
" syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
" hi cFunctions gui=NONE cterm=bold ctermfg=yellow

"为Oracle 数据库开发 pro*C 程序高亮
autocmd BufEnter *.pc set filetype=esqlc


"vim 配色相关配置
"set t_Co=256
"colorscheme molokai
"colorscheme corporation
"colorscheme solarized
"colorscheme morning

" YouCompleteMe相关配置
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='/root/.vim/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 1 " C/C++语法检查提示,1开 0关
let g:ycm_complete_in_comments=1 " 补全功能在注释中同样有效
let g:ycm_confirm_extra_conf=0 " 允许 vim 加载 .ycm_extra_conf.py 文件,不再提示
let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 标签补全引擎
let g:ycm_min_num_of_chars_for_completion=1 " 从第一个键入字符就开始罗列匹配项
let g:ycm_cache_omnifunc=0 " 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全
let g:ycm_goto_buffer_command = 'horizontal-split' " 跳转打开上下分屏
map <F2> :YcmCompleter GoToDefinition<CR>
map <F3> :YcmCompleter GoToDeclaration<CR>
map <F4> :YcmCompleter GoToDefinitionElseDeclaration<CR>
map ycm :YcmDiags<CR>


"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

"NERDTree 文件浏览配置
map <F5> :NERDTreeMirror<CR>
map <F5> :NERDTreeToggle<CR>

"NERD_commenter注释插件配置
let mapleader = ","
let NERDSpaceDelims=1 " 让注释符与语句之间留一个空格
let NERDCompactSexyComs=1 " 多行注释时样子更好看
let g:NERDDefaultAlign = 'left' "将行注释符左对齐
[root@CentOS ~]#