yshen's vim settings

写代码的时候手需要时刻保持在键盘上,随机定位代码、随机删除代码、移动代码、插入代码的操作大大多于阅读、翻页操作,中间卡顿一下效率就大大降低了;vim通过其强大的快捷键,可以完全摆脱鼠标。真是编程利器。通过插件,可以实现强大的IDE的功能。可以说每一个geek都有自己的vim配置,在这里我把我的配置共享出来。

image_1b3rg746h1dpr29dsdu74o1u4qm.png-396.6kB

安装的插件有

  1. 插件管理
    Vundle
  2. 索引提示
    ctag 生成工程的符号文件
    cscope 生成工程符号文件引用关系
    Tagbar 右边栏显示文件中的符号
  3. 自动完成
    echofunc.vim 显示函数定义
    OmniCppComplete 提示结构体成员
    SuperTab TAB键自动完成
  4. 文件浏览
    The-NERD-tree
    ctrlp.vim
  5. 其他
    molokai 配色主题
    c-standard-functions-highlight 高亮C语言函数

使用方法:

  1. 安装Vundle
  2. 复制如下脚本到vimrc
  3. 进入vim之后运行:PluginUpdate

配置文件开源在git上:https://github.com/shenyuflying/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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
"-----------------------------------------------------------
" yshen's vim settings
"----------------------------------------------------------
"
" PLUGINS
" ---------
" 1.插件管理
" Vundle
" 2.索引提示
" ctag 生成工程的符号文件
" cscope 生成工程符号文件引用关系
" Tagbar 右边栏显示文件中的符号
" 3.自动完成
" echofunc.vim 显示函数定义
" OmniCppComplete 提示结构体成员
" SuperTab TAB键自动完成
" 4.文件浏览
" The-NERD-tree
" ctrlp.vim
" 5.其他
" molokai 配色主题
" c-standard-functions-highlight 高亮C语言函数
"
"
" HOWTO
" ----------
" 1.快捷键映射
" <F1>
" <F2> 显示目录窗口
" <F3> 显示符号窗口
" <F4> 生成工程的符号文件
"
" <F5> 高亮文本中的符号
" <F6>
" <F7>
" <F8>
"
" <F9>
" <F10>
" <F11>
" <F12>
"
" INSTALL
" ---------
" 1. Install Vundle first
" 2. Install plugin by Vundle using :PluginUpdate
" 3. Copy this setting in your ~/.vimrc
"
"-----------------------------------------------------------
" Vundle settings
"----------------------------------------------------------
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"Plugin 'Valloric/YouCompleteMe'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
Plugin 'vim-airline/vim-airline'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
"Plugin 'ascenator/L9', {'name': 'newL9'}
"Plugin 'taglist.vim'
Plugin 'Tagbar'
Plugin 'The-NERD-tree'
Plugin 'c-standard-functions-highlight'
Plugin 'molokai'
Plugin 'ctrlp.vim'
Plugin 'echofunc.vim'
Plugin 'OmniCppComplete'
"Plugin 'Syntastic'
Plugin 'SuperTab'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
"
"-----------------------------------------------------------
" generic vim settings
"----------------------------------------------------------
" 显示行号
set nu
" tab键为4个空格
set ts=4
"忽略大小写检索
"set ignorecase
"输入检索时动态变化
set incsearch
"检索高亮
set hlsearch
" 突出显示当前行
"set cursorline
" 打开状态栏标尺
set ruler
" 语法高亮
syntax on
" 在INSERT模式下移动
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
" 设置匹配模式,显示匹配的括号
set showmatch
" 使用鼠标
"set mouse=a
"自动缩进
"set shiftwidth=4
"set softtabstop=4
"set tabstop=4
"set cindent
"set autoindent
"set noautoindent
"set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
set smartindent
"-----------------------------------------------------------
" build
"----------------------------------------------------------
"map <F5> :!make<CR>
"-----------------------------------------------------------
" ctags
"----------------------------------------------------------
set tags=./
set tags=tags;
"生成tag cscope tags.vim等符号文件
map <F4> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . && cscope -Rbq && awk '{print "syntax keyword tag "$1}' tags > tags.vim <CR>
"映射F4在插入模式下也可以用
imap <F4> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . && cscope -Rbq && awk '{print "syntax keyword tag "$1}' tags > tags.vim<CR>
map <F5> :so tags.vim<CR>
imap <F5> <ESC> :so tags.vim<CR>
"-----------------------------------------------------------
" tagbar
"----------------------------------------------------------
"type help: tagbar for more info
let g:tagbar_ctags_bin='ctags' "ctags程序的路径
let g:tagbar_width=30 "窗口宽度的设置
"let g:tagbar_left = 1
let g:tagbar_right = 1
map <F3> :Tagbar<CR>
"autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen() "如果是c语言的程序的话,tagbar自动开启
"-----------------------------------------------------------
" NERDTree
"----------------------------------------------------------
"type help: nerdtree for more info
"autocmd vimenter * NERDTree "自动打开NERDTree
map <F2> :NERDTreeToggle<CR> "打开和关闭的快捷键
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif "自动关闭
"-----------------------------------------------------------
" Cscope
"----------------------------------------------------------
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
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
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
" Using 'CTRL-spacebar' then a search type makes the vim window
" split horizontally, with search result displayed in
" the new window.
nmap <C-\>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :scs find d <C-R>=expand("<cword>")<CR><CR>
" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one
nmap <C-\><C-\>s
\:vert scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>g
\:vert scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>c
\:vert scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>t
\:vert scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>e
\:vert scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\><C-\>i
\:vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\><C-\>d
\:vert scs find d <C-R>=expand("<cword>")<CR><CR>
"-----------------------------------------------------------
" color scheme
" https://github.com/altercation/vim-colors-solarized
" https://github.com/tomasr/molokai
"----------------------------------------------------------
"set background=light
"colorscheme solarized
"set background=dark
"colorscheme solarized
colorscheme molokai
let g:molokai_original = 1
"-----------------------------------------------------------
" auto complete
" https://github.com/vim-scripts/OmniCppComplete
"----------------------------------------------------------
let OmniCpp_MayCompleteDot = 1 " 输入 . 后自动补全
let OmniCpp_MayCompleteArrow = 1 " 输入 -> 后自动补全
let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全
let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表
"-----------------------------------------------------------
" syntastic
" https://github.com/vim-syntastic/syntastic
"----------------------------------------------------------
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

参考

http://www.vim.org/
https://www.zhihu.com/question/26713049/answer/33887444
https://github.com/VundleVim/Vundle.vim/wiki/Examples

如果还想看到更多此类文章,请移步到小宇的博客

文章目录
  1. 1. 参考
|