" ----------------- Author: Fly
" ----------------- Email: fly@baidu.com
" ----------------- Date: 2012-01-04
" Ctrl + K --光标移上一行末尾
" Ctrl + H --光标移行首
" Ctrl + L --光标移行尾
" Ctrl + Z --取代ESC模式键 [和Lingos快捷键有冲突]
" Ctrl + S --保存文件
011
" Ctrl + C --编译 [支持C/C++、Java、Haskell]
012
" Ctrl + R --运行 [支持C/C++、Java、Haskell、Lua、Perl、Python、Ruby]
013
" Ctrl + ] --转到函数定义
014
" Ctrl + T --返回调用函数
015
" Ctrl + E --添加注释 [插入模式下] [添加的是C语言的行注释,所以适用于C/C++/Java等]
016
" Ctrl + E --一步加载语法模板和作者、时间信息 [非插入模式下] [本质是:LoadTemplate和:AuthorInfoDetect的结合]
017
018
" <C-P> --单词补全
019
" <C-X><C-L> --整行补全
020
" Tab键 --插入模式下的全功能语法结构补全 [snipMate插件]
021
022
" wm --开启文档浏览窗口
023
" \ww --进入vimWiki模式
024
025
" za --打开或关闭当前折叠
026
" zM --关闭所有折叠
027
" zR --打开所有折叠
028
029
" :set syntax=cpp --手动选择语法高亮 [或 :set filetype=cpp]
030
031
" :%!xxd --转储二进制文件,以十六进制形式显示
032
" :%!xxd -r --还原二进制文件
033
034
035
036
" ---------- 主要插件详细用法说明 ---------------------
037
038
" :Tlist --呼出变量和函数列表 [TagList插件]
039
" :FencView --查看文件编码和更改文件编码 [FencView插件]
040
" :LoadTemplate --呼出语法模板 [Load_Template插件]
041
" :AuthorInfoDetect --添加作者、时间等信息 [NERD_commenter && authorinfo插件]
042
043
" ---------- a.vim [自动切换C/C++同名头文件] ----------
044
"
045
" :A --切换同名头文件并独占整个屏幕
046
" :AS --切换同名头文件并垂直分屏,头文件在上
047
" :AV --切换同名头文件并水平分割,头文件在左
048
049
" ---------- mark.vim [追踪高亮指定关键字] ------------
050
"
051
" \m --normal模式下,在想要高亮的单词上面敲击\m即可高亮或取消高亮该单词
052
" :Mark --取消所有高亮
053
" :Mark abc --指定高亮单词 abc 或取消高亮 abc
054
055
" ---------- NERDTree [智能文件浏览器] ----------------
056
"
057
" :NERDTree --启动NERDTree插件
058
" o [小写] --切换当前文件或目录的打开、关闭状态
059
" u --打开上层目录
060
" p [小写] --返回上层目录
061
" P [大写] --返回根目录
062
" K --转到当前目录第一个节点
063
" J --转到当前目录最后的节点
064
" m --显示文件系统菜单 [增、删、移]
065
" ? --弹出帮助菜单
066
" q --退出该插件
067
068
" ---------- snipMate [语法结构补全] -------------------
069
" --------- 例如:在编辑C/C++源文件时,输入单词main,然后按TAB键,Vim将自动补全成完整的main函数
070
" --------- 更多补全请自行查看vimfiles目录下的snippets文件夹
071
" --------- 此处只说明了C/C++的补全用法,很多经过了我的修改和调整,你也可以自行调整成适合自己的补全样式
072
"
073
" main -- C/C++语言 main 函数
074
" inc -- #include <>
075
" iinc -- #include ""
076
" incs -- #include <stdio.h> or #include <iostream>
077
" using -- using namespace std;
078
" def -- #define
079
" un -- unsigned
080
" re -- return
081
" p -- printf("\n");
082
" s -- scanf("");
083
" fpr -- fprintf(abc, "\n");
084
" if -- if(){}
085
" elif -- elseif(){}
086
" el -- else{}
087
" t -- a ? b : c
088
" do -- do{}while();
089
" wh -- while(){}
090
" for -- for(){}
091
" forr -- for(i = 0; i < 10; i++){}
092
" cl -- class abc{};
093
" fun -- void abc(){}
094
" fund -- void abc();
095
" td -- typedef a b;
096
" st -- struct abc{};
097
" tds -- typedef struct _abc{}abc;
098
" tde -- typedef enum{};
099
" . -- []
100
101
102
103
104
105
" 配色方案
106
colorscheme desert " 灰褐色
107
108
" 字体、字号
109
set guifont=Courier\ New:h10
110
111
set tabstop=4 " 设置tab键的宽度
112
set shiftwidth=4 " 换行时行间交错使用4个空格
113
set autoindent " 自动对齐
114
set backspace=2 " 设置退格键可用
115
set cindent shiftwidth=4 " 自动缩进4空格
116
set smartindent " 智能自动缩进
117
set ai! " 设置自动缩进
118
set nu! " 显示行号
119
"set showmatch " 显示括号配对情况
120
set mouse=a " 启用鼠标
121
set ruler " 右下角显示光标位置的状态行
122
set incsearch " 查找book时,当输入/b时会自动找到
123
set hlsearch " 开启高亮显示结果
124
set incsearch " 开启实时搜索功能
125
set nowrapscan " 搜索到文件两端时不重新搜索
126
set nocompatible " 关闭兼容模式
127
set vb t_vb= " 关闭提示音
128
"set cursorline " 突出显示当前行
129
set hidden " 允许在有未保存的修改时切换缓冲区
130
set list " 显示Tab符,使用一高亮竖线代替
131
set listchars=tab:\|\ ,
132
133
134
syntax enable " 打开语法高亮
135
syntax on " 开启文件类型侦测
136
filetype indent on " 针对不同的文件类型采用不同的缩进格式
137
filetype plugin on " 针对不同的文件类型加载对应的插件
138
filetype plugin indent on
139
140
if has("gui_running")
141
au GUIEnter * simalt ~x " 窗口启动时自动最大化
142
"set guioptions-=m " 隐藏菜单栏
143
set guioptions-=T " 隐藏工具栏
144
"set guioptions-=L " 隐藏左侧滚动条
145
"set guioptions-=r " 隐藏右侧滚动条
146
"set guioptions-=b " 隐藏底部滚动条
147
"set showtabline=0 " 隐藏Tab栏
148
endif
149
150
set writebackup " 设置无备份文件
151
set nobackup
152
set autochdir " 设定文件浏览器目录为当前目录
153
"set nowrap " 设置不自动换行
154
set foldmethod=syntax " 选择代码折叠类型
155
set foldlevel=100 " 禁止自动折叠
156
157
" 每行超过80个的字符用下划线标示
158
au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/
159
160
161
" 编码设置
162
"set encoding=utf-8
163
set fileencodings=utf-8,cp936,gbk,gb18030,big5,latin1
164
165
166
" For Haskell
167
:let hs_highlight_delimiters=1 " 高亮定界符
168
:let hs_highlight_boolean=1 " 把True和False识别为关键字
169
:let hs_highlight_types=1 " 把基本类型的名字识别为关键字
170
:let hs_highlight_more_types=1 " 把更多常用类型识别为关键字
171
:let hs_highlight_debug=1 " 高亮调试函数的名字
172
:let hs_allow_hash_operator=1 " 阻止把#高亮为错误
173
174
175
set laststatus=2 " 开启状态栏信息
176
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
177
178
" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]
179
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
180
181
182
183
" ######### 括号、引号、中括号等自动匹配 ######### "
184
185
:inoremap ( ()<ESC>i
186
187
:inoremap ) <c-r>=ClosePair(')')<CR>
188
189
:inoremap { {}<ESC>i
190
191
:inoremap } <c-r>=ClosePair('}')<CR>
192
193
:inoremap [ []<ESC>i
194
195
:inoremap ] <c-r>=ClosePair(']')<CR>
196
197
":inoremap < <><ESC>i
198
199
":inoremap > <c-r>=ClosePair('>')<CR>
200
201
:inoremap " ""<ESC>i
202
203
:inoremap ' ''<ESC>i
204
205
:inoremap ` ``<ESC>i
206
207
function ClosePair(char)
208
if getline('.')[col('.') - 1] == a:char
209
return "\<Right>"
210
else
211
return a:char
212
endif
213
endf
214
215
216
217
218
" ######### 自定义快捷键 ######### "
219
220
" Ctrl + K 将光标移到上一行的末尾
221
imap <ESC>kA
222
223
" Ctrl + L 将光标移到行尾
224
imap <ESC>A
225
226
" Ctrl + H 将光标移到行首
227
imap <ESC>I
228
229
" Ctrl + Z 取代ESC模式键
230
:inoremap <ESC>
231
232
" Ctrl + S 保存文件
233
map <ESC>:w<CR>
234
imap <ESC>:w<CR>a
235
vmap <ESC>:w<CR>
236
237
" Ctrl + E 一步加载语法模板和作者、时间信息 [非插入模式]
238
map <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
239
vmap <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
240
241
" Ctrl + E 在当前行添加C语言行注释 [插入模式]
242
imap /* */<ESC>hhi
243
244
245
246
247
248
" ######### 第三方插件 ######### "
249
250
" WinManager 直接输入 wm 命令即可开启文件浏览窗口
251
let g:winManagerWindowLayout='FileExplorer'
252
nmap wm :WMToggle<cr>
253
254
" MiniBufExplorer 多个文件切换 可使用鼠标双击相应文件名进行切换
255
let g:miniBufExplMapWindowNavVim=1
256
let g:miniBufExplMapWindowNavArrows=1
257
let g:miniBufExplMapCTabSwitchBufs=1
258
let g:miniBufExplModSelTarget=1
259
260
" TagList 键入:Tlist开启
261
let Tlist_Show_One_File=1 " 只显示当前文件的tags
262
let Tlist_Exit_OnlyWindow=1 " 如果Taglist窗口是最后一个窗口则退出Vim
263
let Tlist_Use_Right_Window=1 " 在右侧窗口中显示
264
265
" ctags
266
" --先在项目顶层目录执行ctags -R,然后打开源文件,在命令模式中执行如:set tags=../../tags
267
" --这样在函数名上按 <C-]> 即可转到函数定义,按 <C-T> 可以返回调用地址
268
" --如果长时间需要在该目录工作,也可以将tags路径写入配置文件
269
270
"set tags+=C:\Develop\MinGW\include\tags " For C/C++
271
"set tags+=C:\Develop\GTK\include\tags " For GTK+
272
"set tags+=C:\Develop\Lua\lua\tags " For Lua
273
"set tags+=G:\Cygwin\usr\include\tags " For Cygwin
274
275
" TxtBrowser 高亮TXT文本文件
276
au BufRead,BufNewFile *.txt setlocal ft=txt
277
278
" fencview 自动编码识别 :FencView 查看文件编码和更改文件编码
279
let g:fencview_autodetect=1
280
281
" Load_Template 根据文件后缀自动加载模板,使用:LoadTemplate呼出
282
let g:template_path='D:\Apps\Gvim\vimfiles\template\'
283
284
" NERD_commenter && authorinfo 自动添加作者、时间等信息,使用:AuthorInfoDetect呼出
285
let g:vimrc_author='Ruchee'
286
let g:vimrc_email='my@ruchee.com'
287
let g:vimrc_homepage='http://www.ruchee.com'
288
289
290
291
292
293
" ######### 一键保存和编译 ######### "
294
" ######### 如此处没有配置你需要的编程语言,请参照示例自行配置,很简单的
295
296
" 编译C源文件
297
func! CompileGcc()
298
exec "w"
299
let compilecmd="!gcc -Wall -pedantic -std=c99 "
300
let compileflag="-o %<"
301
exec compilecmd." % ".compileflag
302
endfunc
303
304
" 编译C++源文件
305
func! CompileCpp()
306
exec "w"
307
let compilecmd="!g++ -Wall -pedantic -std=c++98 "
308
let compileflag="-o %<"
309
exec compilecmd." % ".compileflag
310
endfunc
311
312
" 编译Java源文件
313
func! CompileJava()
314
exec "w"
315
exec "!javac %"
316
endfunc
317
318
" 编译Haskell源文件
319
func! CompileHaskell()
320
exec "w"
321
let compilecmd="!ghc --make "
322
let compileflag="-o %<"
323
exec compilecmd." % ".compileflag
324
endfunc
325
326
" 运行Lua源文件
327
func! RunLua()
328
exec "w"
329
exec "!lua %"
330
endfunc
331
332
" 运行Perl源文件
333
func! RunPerl()
334
exec "w"
335
exec "!perl %"
336
endfunc
337
338
" 运行Python源文件
339
func! RunPython()
340
exec "w"
341
exec "!python %"
342
endfunc
343
344
" 运行Ruby源文件
345
func! RunRuby()
346
exec "w"
347
exec "!ruby %"
348
endfunc
349
350
351
" 根据文件类型自动选择相应的编译函数
352
func! CompileCode()
353
exec "w"
354
if &filetype == "c"
355
exec "call CompileGcc()"
356
elseif &filetype == "cpp"
357
exec "call CompileCpp()"
358
elseif &filetype == "java"
359
exec "call CompileJava()"
360
elseif &filetype == "haskell"
361
exec "call CompileHaskell()"
362
elseif &filetype == "lua"
363
exec "call RunLua()"
364
elseif &filetype == "perl"
365
exec "call RunPerl()"
366
elseif &filetype == "python"
367
exec "call RunPython()"
368
elseif &filetype == "ruby"
369
exec "call RunRuby()"
370
endif
371
endfunc
372
373
" 运行可执行文件
374
func! RunResult()
375
exec "w"
376
if &filetype == "c"
377
exec "! %<"
378
elseif &filetype == "cpp"
379
exec "! %<"
380
elseif &filetype == "java"
381
exec "!java %<"
382
elseif &filetype == "haskell"
383
exec "! %<"
384
elseif &filetype == "lua"
385
exec "!lua %<.lua"
386
elseif &filetype == "perl"
387
exec "!perl %<.pl"
388
elseif &filetype == "python"
389
exec "!python %<.py"
390
elseif &filetype == "ruby"
391
exec "!ruby %<.rb"
392
endif
393
endfunc
394
395
396
" Ctrl + C 一键保存、编译
397
map :call CompileCode()<CR>
398
imap <ESC>:call CompileCode()<CR>
399
vmap <ESC>:call CompileCode()<CR>
400
401
" Ctrl + R 一键保存、运行
402
map :call RunResult()<CR>
403
imap <ESC>:call RunResult()<CR>
404
vmap <ESC>:call RunResult()<CR>
405
406
407
408
409
" ######### VimWiki 写作助手 ######### "
410
411
" 使用鼠标映射
412
let g:vimwiki_use_mouse = 1
413
414
" 不要将驼峰式词组作为 Wiki 词条
415
let g:vimwiki_camel_case = 0
416
417
" 声明可以在wiki里面使用的HTML标签
418
let g:vimwiki_valid_html_tags='b,i,s,u,sub,sup,kbd,br,hr,div,del,code,red,center,left,right,h4,h5,h6,pre'
419
420
let g:vimwiki_list = [{
421
\ 'path': 'D:/Apps/Gvim/mysite/wiki',
422
\ 'path_html': 'D:/Apps/Gvim/mysite/html/',
423
\ 'html_header': 'D:/Apps/Gvim/mysite/template/header.html',
424
\ 'html_footer': 'D:/Apps/Gvim/mysite/template/footer.html',
425
\ 'auto_export': 1,
426
\ 'nested_syntaxes': {'Asm': 'asm', 'C': 'c', 'C++': 'cpp','Java': 'java', 'Haskell': 'haskell', 'Lua': 'lua', 'Perl': 'perl', 'Python': 'python', 'PHP': 'php', 'HTML': 'html', 'Bash': 'sh', 'Vim': 'vim', 'Make': 'make', 'Automake': 'AUTOMAKE'},}]
[代码] _vimrc(无Vimwiki版)
001
" 配色方案
002
colorscheme desert " 灰褐色
003
004
" 字体、字号
005
set guifont=Courier\ New:h10
006
007
set tabstop=4 " 设置tab键的宽度
008
set shiftwidth=4 " 换行时行间交错使用4个空格
009
set autoindent " 自动对齐
010
set backspace=2 " 设置退格键可用
011
set cindent shiftwidth=4 " 自动缩进4空格
012
set smartindent " 智能自动缩进
013
set ai! " 设置自动缩进
014
set nu! " 显示行号
015
"set showmatch " 显示括号配对情况
016
set mouse=a " 启用鼠标
017
set ruler " 右下角显示光标位置的状态行
018
set incsearch " 查找book时,当输入/b时会自动找到
019
set hlsearch " 开启高亮显示结果
020
set incsearch " 开启实时搜索功能
021
set nowrapscan " 搜索到文件两端时不重新搜索
022
set nocompatible " 关闭兼容模式
023
set vb t_vb= " 关闭提示音
024
"set cursorline " 突出显示当前行
025
set hidden " 允许在有未保存的修改时切换缓冲区
026
set list " 显示Tab符,使用一高亮竖线代替
027
set listchars=tab:\|\ ,
028
029
030
syntax enable " 打开语法高亮
031
syntax on " 开启文件类型侦测
032
filetype indent on " 针对不同的文件类型采用不同的缩进格式
033
filetype plugin on " 针对不同的文件类型加载对应的插件
034
filetype plugin indent on
035
036
if has("gui_running")
037
au GUIEnter * simalt ~x " 窗口启动时自动最大化
038
"set guioptions-=m " 隐藏菜单栏
039
set guioptions-=T " 隐藏工具栏
040
"set guioptions-=L " 隐藏左侧滚动条
041
"set guioptions-=r " 隐藏右侧滚动条
042
"set guioptions-=b " 隐藏底部滚动条
043
"set showtabline=0 " 隐藏Tab栏
044
endif
045
046
set writebackup " 设置无备份文件
047
set nobackup
048
set autochdir " 设定文件浏览器目录为当前目录
049
"set nowrap " 设置不自动换行
050
set foldmethod=syntax " 选择代码折叠类型
051
set foldlevel=100 " 禁止自动折叠
052
053
" 每行超过80个的字符用下划线标示
054
au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/
055
056
057
" 编码设置
058
"set encoding=utf-8
059
set fileencodings=utf-8,cp936,gbk,gb18030,big5,latin1
060
061
062
" For Haskell
063
:let hs_highlight_delimiters=1 " 高亮定界符
064
:let hs_highlight_boolean=1 " 把True和False识别为关键字
065
:let hs_highlight_types=1 " 把基本类型的名字识别为关键字
066
:let hs_highlight_more_types=1 " 把更多常用类型识别为关键字
067
:let hs_highlight_debug=1 " 高亮调试函数的名字
068
:let hs_allow_hash_operator=1 " 阻止把#高亮为错误
069
070
071
set laststatus=2 " 开启状态栏信息
072
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
073
074
" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]
075
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
076
077
078
079
" ######### 括号、引号、中括号等自动匹配 ######### "
080
081
:inoremap ( ()<ESC>i
082
083
:inoremap ) <c-r>=ClosePair(')')<CR>
084
085
:inoremap { {}<ESC>i
086
087
:inoremap } <c-r>=ClosePair('}')<CR>
088
089
:inoremap [ []<ESC>i
090
091
:inoremap ] <c-r>=ClosePair(']')<CR>
092
093
":inoremap < <><ESC>i
094
095
":inoremap > <c-r>=ClosePair('>')<CR>
096
097
:inoremap " ""<ESC>i
098
099
:inoremap ' ''<ESC>i
100
101
:inoremap ` ``<ESC>i
102
103
function ClosePair(char)
104
if getline('.')[col('.') - 1] == a:char
105
return "\<Right>"
106
else
107
return a:char
108
endif
109
endf
110
111
112
113
114
" ######### 自定义快捷键 ######### "
115
116
" Ctrl + K 将光标移到上一行的末尾
117
imap <ESC>kA
118
119
" Ctrl + L 将光标移到行尾
120
imap <ESC>A
121
122
" Ctrl + H 将光标移到行首
123
imap <ESC>I
124
125
" Ctrl + Z 取代ESC模式键
126
:inoremap <ESC>
127
128
" Ctrl + S 保存文件
129
map <ESC>:w<CR>
130
imap <ESC>:w<CR>a
131
vmap <ESC>:w<CR>
132
133
" Ctrl + E 一步加载语法模板和作者、时间信息 [非插入模式]
134
map <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
135
vmap <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
136
137
" Ctrl + E 在当前行添加C语言行注释 [插入模式]
138
imap /* */<ESC>hhi
139
140
141
142
143
144
" ######### 第三方插件 ######### "
145
146
" WinManager 直接输入 wm 命令即可开启文件浏览窗口
147
let g:winManagerWindowLayout='FileExplorer'
148
nmap wm :WMToggle<cr>
149
150
" MiniBufExplorer 多个文件切换 可使用鼠标双击相应文件名进行切换
151
let g:miniBufExplMapWindowNavVim=1
152
let g:miniBufExplMapWindowNavArrows=1
153
let g:miniBufExplMapCTabSwitchBufs=1
154
let g:miniBufExplModSelTarget=1
155
156
" TagList 键入:Tlist开启
157
let Tlist_Show_One_File=1 " 只显示当前文件的tags
158
let Tlist_Exit_OnlyWindow=1 " 如果Taglist窗口是最后一个窗口则退出Vim
159
let Tlist_Use_Right_Window=1 " 在右侧窗口中显示
160
161
" ctags
162
" --先在项目顶层目录执行ctags -R,然后打开源文件,在命令模式中执行如:set tags=../../tags
163
" --这样在函数名上按 <C-]> 即可转到函数定义,按 <C-T> 可以返回调用地址
164
" --如果长时间需要在该目录工作,也可以将tags路径写入配置文件
165
166
"set tags+=C:\Develop\MinGW\include\tags " For C/C++
167
"set tags+=C:\Develop\GTK\include\tags " For GTK+
168
"set tags+=C:\Develop\Lua\lua\tags " For Lua
169
"set tags+=G:\Cygwin\usr\include\tags " For Cygwin
170
171
" TxtBrowser 高亮TXT文本文件
172
au BufRead,BufNewFile *.txt setlocal ft=txt
173
174
" fencview 自动编码识别 :FencView 查看文件编码和更改文件编码
175
let g:fencview_autodetect=1
176
177
" Load_Template 根据文件后缀自动加载模板,使用:LoadTemplate呼出
178
let g:template_path='D:\Apps\Gvim\vimfiles\template\'
179
180
" NERD_commenter && authorinfo 自动添加作者、时间等信息,使用:AuthorInfoDetect呼出
181
let g:vimrc_author='Ruchee'
182
let g:vimrc_email='my@ruchee.com'
183
let g:vimrc_homepage='http://www.ruchee.com'
184
185
186
187
188
189
" ######### 一键保存和编译 ######### "
190
" ######### 如此处没有配置你需要的编程语言,请参照示例自行配置,很简单的
191
192
" 编译C源文件
193
func! CompileGcc()
194
exec "w"
195
let compilecmd="!gcc -Wall -pedantic -std=c99 "
196
let compileflag="-o %<"
197
exec compilecmd." % ".compileflag
198
endfunc
199
200
" 编译C++源文件
201
func! CompileCpp()
202
exec "w"
203
let compilecmd="!g++ -Wall -pedantic -std=c++98 "
204
let compileflag="-o %<"
205
exec compilecmd." % ".compileflag
206
endfunc
207
208
" 编译Java源文件
209
func! CompileJava()
210
exec "w"
211
exec "!javac %"
212
endfunc
213
214
" 编译Haskell源文件
215
func! CompileHaskell()
216
exec "w"
217
let compilecmd="!ghc --make "
218
let compileflag="-o %<"
219
exec compilecmd." % ".compileflag
220
endfunc
221
222
" 运行Lua源文件
223
func! RunLua()
224
exec "w"
225
exec "!lua %"
226
endfunc
227
228
" 运行Perl源文件
229
func! RunPerl()
230
exec "w"
231
exec "!perl %"
232
endfunc
233
234
" 运行Python源文件
235
func! RunPython()
236
exec "w"
237
exec "!python %"
238
endfunc
239
240
" 运行Ruby源文件
241
func! RunRuby()
242
exec "w"
243
exec "!ruby %"
244
endfunc
245
246
247
" 根据文件类型自动选择相应的编译函数
248
func! CompileCode()
249
exec "w"
250
if &filetype == "c"
251
exec "call CompileGcc()"
252
elseif &filetype == "cpp"
253
exec "call CompileCpp()"
254
elseif &filetype == "java"
255
exec "call CompileJava()"
256
elseif &filetype == "haskell"
257
exec "call CompileHaskell()"
258
elseif &filetype == "lua"
259
exec "call RunLua()"
260
elseif &filetype == "perl"
261
exec "call RunPerl()"
262
elseif &filetype == "python"
263
exec "call RunPython()"
264
elseif &filetype == "ruby"
265
exec "call RunRuby()"
266
endif
267
endfunc
268
269
" 运行可执行文件
func! RunResult()
exec "w"
if &filetype == "c"
exec "! %<"
elseif &filetype == "cpp"
exec "! %<"
elseif &filetype == "java"
exec "!java %<"
elseif &filetype == "haskell"
exec "! %<"
elseif &filetype == "lua"
exec "!lua %<.lua"
elseif &filetype == "perl"
exec "!perl %<.pl"
elseif &filetype == "python"
exec "!python %<.py"
elseif &filetype == "ruby"
exec "!ruby %<.rb"
endif
endfunc
" Ctrl + C 一键保存、编译
map :call CompileCode()<CR>
imap <ESC>:call CompileCode()<CR>
vmap <ESC>:call CompileCode()<CR>
" Ctrl + R 一键保存、运行
map :call RunResult()<CR>
imap <ESC>:call RunResult()<CR>
vmap <ESC>:call RunResult()<CR>
" ----------------- Email: fly@baidu.com
" ----------------- Date: 2012-01-04
" Ctrl + K --光标移上一行末尾
" Ctrl + H --光标移行首
" Ctrl + L --光标移行尾
" Ctrl + Z --取代ESC模式键 [和Lingos快捷键有冲突]
" Ctrl + S --保存文件
011
" Ctrl + C --编译 [支持C/C++、Java、Haskell]
012
" Ctrl + R --运行 [支持C/C++、Java、Haskell、Lua、Perl、Python、Ruby]
013
" Ctrl + ] --转到函数定义
014
" Ctrl + T --返回调用函数
015
" Ctrl + E --添加注释 [插入模式下] [添加的是C语言的行注释,所以适用于C/C++/Java等]
016
" Ctrl + E --一步加载语法模板和作者、时间信息 [非插入模式下] [本质是:LoadTemplate和:AuthorInfoDetect的结合]
017
018
" <C-P> --单词补全
019
" <C-X><C-L> --整行补全
020
" Tab键 --插入模式下的全功能语法结构补全 [snipMate插件]
021
022
" wm --开启文档浏览窗口
023
" \ww --进入vimWiki模式
024
025
" za --打开或关闭当前折叠
026
" zM --关闭所有折叠
027
" zR --打开所有折叠
028
029
" :set syntax=cpp --手动选择语法高亮 [或 :set filetype=cpp]
030
031
" :%!xxd --转储二进制文件,以十六进制形式显示
032
" :%!xxd -r --还原二进制文件
033
034
035
036
" ---------- 主要插件详细用法说明 ---------------------
037
038
" :Tlist --呼出变量和函数列表 [TagList插件]
039
" :FencView --查看文件编码和更改文件编码 [FencView插件]
040
" :LoadTemplate --呼出语法模板 [Load_Template插件]
041
" :AuthorInfoDetect --添加作者、时间等信息 [NERD_commenter && authorinfo插件]
042
043
" ---------- a.vim [自动切换C/C++同名头文件] ----------
044
"
045
" :A --切换同名头文件并独占整个屏幕
046
" :AS --切换同名头文件并垂直分屏,头文件在上
047
" :AV --切换同名头文件并水平分割,头文件在左
048
049
" ---------- mark.vim [追踪高亮指定关键字] ------------
050
"
051
" \m --normal模式下,在想要高亮的单词上面敲击\m即可高亮或取消高亮该单词
052
" :Mark --取消所有高亮
053
" :Mark abc --指定高亮单词 abc 或取消高亮 abc
054
055
" ---------- NERDTree [智能文件浏览器] ----------------
056
"
057
" :NERDTree --启动NERDTree插件
058
" o [小写] --切换当前文件或目录的打开、关闭状态
059
" u --打开上层目录
060
" p [小写] --返回上层目录
061
" P [大写] --返回根目录
062
" K --转到当前目录第一个节点
063
" J --转到当前目录最后的节点
064
" m --显示文件系统菜单 [增、删、移]
065
" ? --弹出帮助菜单
066
" q --退出该插件
067
068
" ---------- snipMate [语法结构补全] -------------------
069
" --------- 例如:在编辑C/C++源文件时,输入单词main,然后按TAB键,Vim将自动补全成完整的main函数
070
" --------- 更多补全请自行查看vimfiles目录下的snippets文件夹
071
" --------- 此处只说明了C/C++的补全用法,很多经过了我的修改和调整,你也可以自行调整成适合自己的补全样式
072
"
073
" main -- C/C++语言 main 函数
074
" inc -- #include <>
075
" iinc -- #include ""
076
" incs -- #include <stdio.h> or #include <iostream>
077
" using -- using namespace std;
078
" def -- #define
079
" un -- unsigned
080
" re -- return
081
" p -- printf("\n");
082
" s -- scanf("");
083
" fpr -- fprintf(abc, "\n");
084
" if -- if(){}
085
" elif -- elseif(){}
086
" el -- else{}
087
" t -- a ? b : c
088
" do -- do{}while();
089
" wh -- while(){}
090
" for -- for(){}
091
" forr -- for(i = 0; i < 10; i++){}
092
" cl -- class abc{};
093
" fun -- void abc(){}
094
" fund -- void abc();
095
" td -- typedef a b;
096
" st -- struct abc{};
097
" tds -- typedef struct _abc{}abc;
098
" tde -- typedef enum{};
099
" . -- []
100
101
102
103
104
105
" 配色方案
106
colorscheme desert " 灰褐色
107
108
" 字体、字号
109
set guifont=Courier\ New:h10
110
111
set tabstop=4 " 设置tab键的宽度
112
set shiftwidth=4 " 换行时行间交错使用4个空格
113
set autoindent " 自动对齐
114
set backspace=2 " 设置退格键可用
115
set cindent shiftwidth=4 " 自动缩进4空格
116
set smartindent " 智能自动缩进
117
set ai! " 设置自动缩进
118
set nu! " 显示行号
119
"set showmatch " 显示括号配对情况
120
set mouse=a " 启用鼠标
121
set ruler " 右下角显示光标位置的状态行
122
set incsearch " 查找book时,当输入/b时会自动找到
123
set hlsearch " 开启高亮显示结果
124
set incsearch " 开启实时搜索功能
125
set nowrapscan " 搜索到文件两端时不重新搜索
126
set nocompatible " 关闭兼容模式
127
set vb t_vb= " 关闭提示音
128
"set cursorline " 突出显示当前行
129
set hidden " 允许在有未保存的修改时切换缓冲区
130
set list " 显示Tab符,使用一高亮竖线代替
131
set listchars=tab:\|\ ,
132
133
134
syntax enable " 打开语法高亮
135
syntax on " 开启文件类型侦测
136
filetype indent on " 针对不同的文件类型采用不同的缩进格式
137
filetype plugin on " 针对不同的文件类型加载对应的插件
138
filetype plugin indent on
139
140
if has("gui_running")
141
au GUIEnter * simalt ~x " 窗口启动时自动最大化
142
"set guioptions-=m " 隐藏菜单栏
143
set guioptions-=T " 隐藏工具栏
144
"set guioptions-=L " 隐藏左侧滚动条
145
"set guioptions-=r " 隐藏右侧滚动条
146
"set guioptions-=b " 隐藏底部滚动条
147
"set showtabline=0 " 隐藏Tab栏
148
endif
149
150
set writebackup " 设置无备份文件
151
set nobackup
152
set autochdir " 设定文件浏览器目录为当前目录
153
"set nowrap " 设置不自动换行
154
set foldmethod=syntax " 选择代码折叠类型
155
set foldlevel=100 " 禁止自动折叠
156
157
" 每行超过80个的字符用下划线标示
158
au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/
159
160
161
" 编码设置
162
"set encoding=utf-8
163
set fileencodings=utf-8,cp936,gbk,gb18030,big5,latin1
164
165
166
" For Haskell
167
:let hs_highlight_delimiters=1 " 高亮定界符
168
:let hs_highlight_boolean=1 " 把True和False识别为关键字
169
:let hs_highlight_types=1 " 把基本类型的名字识别为关键字
170
:let hs_highlight_more_types=1 " 把更多常用类型识别为关键字
171
:let hs_highlight_debug=1 " 高亮调试函数的名字
172
:let hs_allow_hash_operator=1 " 阻止把#高亮为错误
173
174
175
set laststatus=2 " 开启状态栏信息
176
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
177
178
" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]
179
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
180
181
182
183
" ######### 括号、引号、中括号等自动匹配 ######### "
184
185
:inoremap ( ()<ESC>i
186
187
:inoremap ) <c-r>=ClosePair(')')<CR>
188
189
:inoremap { {}<ESC>i
190
191
:inoremap } <c-r>=ClosePair('}')<CR>
192
193
:inoremap [ []<ESC>i
194
195
:inoremap ] <c-r>=ClosePair(']')<CR>
196
197
":inoremap < <><ESC>i
198
199
":inoremap > <c-r>=ClosePair('>')<CR>
200
201
:inoremap " ""<ESC>i
202
203
:inoremap ' ''<ESC>i
204
205
:inoremap ` ``<ESC>i
206
207
function ClosePair(char)
208
if getline('.')[col('.') - 1] == a:char
209
return "\<Right>"
210
else
211
return a:char
212
endif
213
endf
214
215
216
217
218
" ######### 自定义快捷键 ######### "
219
220
" Ctrl + K 将光标移到上一行的末尾
221
imap <ESC>kA
222
223
" Ctrl + L 将光标移到行尾
224
imap <ESC>A
225
226
" Ctrl + H 将光标移到行首
227
imap <ESC>I
228
229
" Ctrl + Z 取代ESC模式键
230
:inoremap <ESC>
231
232
" Ctrl + S 保存文件
233
map <ESC>:w<CR>
234
imap <ESC>:w<CR>a
235
vmap <ESC>:w<CR>
236
237
" Ctrl + E 一步加载语法模板和作者、时间信息 [非插入模式]
238
map <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
239
vmap <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
240
241
" Ctrl + E 在当前行添加C语言行注释 [插入模式]
242
imap /* */<ESC>hhi
243
244
245
246
247
248
" ######### 第三方插件 ######### "
249
250
" WinManager 直接输入 wm 命令即可开启文件浏览窗口
251
let g:winManagerWindowLayout='FileExplorer'
252
nmap wm :WMToggle<cr>
253
254
" MiniBufExplorer 多个文件切换 可使用鼠标双击相应文件名进行切换
255
let g:miniBufExplMapWindowNavVim=1
256
let g:miniBufExplMapWindowNavArrows=1
257
let g:miniBufExplMapCTabSwitchBufs=1
258
let g:miniBufExplModSelTarget=1
259
260
" TagList 键入:Tlist开启
261
let Tlist_Show_One_File=1 " 只显示当前文件的tags
262
let Tlist_Exit_OnlyWindow=1 " 如果Taglist窗口是最后一个窗口则退出Vim
263
let Tlist_Use_Right_Window=1 " 在右侧窗口中显示
264
265
" ctags
266
" --先在项目顶层目录执行ctags -R,然后打开源文件,在命令模式中执行如:set tags=../../tags
267
" --这样在函数名上按 <C-]> 即可转到函数定义,按 <C-T> 可以返回调用地址
268
" --如果长时间需要在该目录工作,也可以将tags路径写入配置文件
269
270
"set tags+=C:\Develop\MinGW\include\tags " For C/C++
271
"set tags+=C:\Develop\GTK\include\tags " For GTK+
272
"set tags+=C:\Develop\Lua\lua\tags " For Lua
273
"set tags+=G:\Cygwin\usr\include\tags " For Cygwin
274
275
" TxtBrowser 高亮TXT文本文件
276
au BufRead,BufNewFile *.txt setlocal ft=txt
277
278
" fencview 自动编码识别 :FencView 查看文件编码和更改文件编码
279
let g:fencview_autodetect=1
280
281
" Load_Template 根据文件后缀自动加载模板,使用:LoadTemplate呼出
282
let g:template_path='D:\Apps\Gvim\vimfiles\template\'
283
284
" NERD_commenter && authorinfo 自动添加作者、时间等信息,使用:AuthorInfoDetect呼出
285
let g:vimrc_author='Ruchee'
286
let g:vimrc_email='my@ruchee.com'
287
let g:vimrc_homepage='http://www.ruchee.com'
288
289
290
291
292
293
" ######### 一键保存和编译 ######### "
294
" ######### 如此处没有配置你需要的编程语言,请参照示例自行配置,很简单的
295
296
" 编译C源文件
297
func! CompileGcc()
298
exec "w"
299
let compilecmd="!gcc -Wall -pedantic -std=c99 "
300
let compileflag="-o %<"
301
exec compilecmd." % ".compileflag
302
endfunc
303
304
" 编译C++源文件
305
func! CompileCpp()
306
exec "w"
307
let compilecmd="!g++ -Wall -pedantic -std=c++98 "
308
let compileflag="-o %<"
309
exec compilecmd." % ".compileflag
310
endfunc
311
312
" 编译Java源文件
313
func! CompileJava()
314
exec "w"
315
exec "!javac %"
316
endfunc
317
318
" 编译Haskell源文件
319
func! CompileHaskell()
320
exec "w"
321
let compilecmd="!ghc --make "
322
let compileflag="-o %<"
323
exec compilecmd." % ".compileflag
324
endfunc
325
326
" 运行Lua源文件
327
func! RunLua()
328
exec "w"
329
exec "!lua %"
330
endfunc
331
332
" 运行Perl源文件
333
func! RunPerl()
334
exec "w"
335
exec "!perl %"
336
endfunc
337
338
" 运行Python源文件
339
func! RunPython()
340
exec "w"
341
exec "!python %"
342
endfunc
343
344
" 运行Ruby源文件
345
func! RunRuby()
346
exec "w"
347
exec "!ruby %"
348
endfunc
349
350
351
" 根据文件类型自动选择相应的编译函数
352
func! CompileCode()
353
exec "w"
354
if &filetype == "c"
355
exec "call CompileGcc()"
356
elseif &filetype == "cpp"
357
exec "call CompileCpp()"
358
elseif &filetype == "java"
359
exec "call CompileJava()"
360
elseif &filetype == "haskell"
361
exec "call CompileHaskell()"
362
elseif &filetype == "lua"
363
exec "call RunLua()"
364
elseif &filetype == "perl"
365
exec "call RunPerl()"
366
elseif &filetype == "python"
367
exec "call RunPython()"
368
elseif &filetype == "ruby"
369
exec "call RunRuby()"
370
endif
371
endfunc
372
373
" 运行可执行文件
374
func! RunResult()
375
exec "w"
376
if &filetype == "c"
377
exec "! %<"
378
elseif &filetype == "cpp"
379
exec "! %<"
380
elseif &filetype == "java"
381
exec "!java %<"
382
elseif &filetype == "haskell"
383
exec "! %<"
384
elseif &filetype == "lua"
385
exec "!lua %<.lua"
386
elseif &filetype == "perl"
387
exec "!perl %<.pl"
388
elseif &filetype == "python"
389
exec "!python %<.py"
390
elseif &filetype == "ruby"
391
exec "!ruby %<.rb"
392
endif
393
endfunc
394
395
396
" Ctrl + C 一键保存、编译
397
map :call CompileCode()<CR>
398
imap <ESC>:call CompileCode()<CR>
399
vmap <ESC>:call CompileCode()<CR>
400
401
" Ctrl + R 一键保存、运行
402
map :call RunResult()<CR>
403
imap <ESC>:call RunResult()<CR>
404
vmap <ESC>:call RunResult()<CR>
405
406
407
408
409
" ######### VimWiki 写作助手 ######### "
410
411
" 使用鼠标映射
412
let g:vimwiki_use_mouse = 1
413
414
" 不要将驼峰式词组作为 Wiki 词条
415
let g:vimwiki_camel_case = 0
416
417
" 声明可以在wiki里面使用的HTML标签
418
let g:vimwiki_valid_html_tags='b,i,s,u,sub,sup,kbd,br,hr,div,del,code,red,center,left,right,h4,h5,h6,pre'
419
420
let g:vimwiki_list = [{
421
\ 'path': 'D:/Apps/Gvim/mysite/wiki',
422
\ 'path_html': 'D:/Apps/Gvim/mysite/html/',
423
\ 'html_header': 'D:/Apps/Gvim/mysite/template/header.html',
424
\ 'html_footer': 'D:/Apps/Gvim/mysite/template/footer.html',
425
\ 'auto_export': 1,
426
\ 'nested_syntaxes': {'Asm': 'asm', 'C': 'c', 'C++': 'cpp','Java': 'java', 'Haskell': 'haskell', 'Lua': 'lua', 'Perl': 'perl', 'Python': 'python', 'PHP': 'php', 'HTML': 'html', 'Bash': 'sh', 'Vim': 'vim', 'Make': 'make', 'Automake': 'AUTOMAKE'},}]
[代码] _vimrc(无Vimwiki版)
001
" 配色方案
002
colorscheme desert " 灰褐色
003
004
" 字体、字号
005
set guifont=Courier\ New:h10
006
007
set tabstop=4 " 设置tab键的宽度
008
set shiftwidth=4 " 换行时行间交错使用4个空格
009
set autoindent " 自动对齐
010
set backspace=2 " 设置退格键可用
011
set cindent shiftwidth=4 " 自动缩进4空格
012
set smartindent " 智能自动缩进
013
set ai! " 设置自动缩进
014
set nu! " 显示行号
015
"set showmatch " 显示括号配对情况
016
set mouse=a " 启用鼠标
017
set ruler " 右下角显示光标位置的状态行
018
set incsearch " 查找book时,当输入/b时会自动找到
019
set hlsearch " 开启高亮显示结果
020
set incsearch " 开启实时搜索功能
021
set nowrapscan " 搜索到文件两端时不重新搜索
022
set nocompatible " 关闭兼容模式
023
set vb t_vb= " 关闭提示音
024
"set cursorline " 突出显示当前行
025
set hidden " 允许在有未保存的修改时切换缓冲区
026
set list " 显示Tab符,使用一高亮竖线代替
027
set listchars=tab:\|\ ,
028
029
030
syntax enable " 打开语法高亮
031
syntax on " 开启文件类型侦测
032
filetype indent on " 针对不同的文件类型采用不同的缩进格式
033
filetype plugin on " 针对不同的文件类型加载对应的插件
034
filetype plugin indent on
035
036
if has("gui_running")
037
au GUIEnter * simalt ~x " 窗口启动时自动最大化
038
"set guioptions-=m " 隐藏菜单栏
039
set guioptions-=T " 隐藏工具栏
040
"set guioptions-=L " 隐藏左侧滚动条
041
"set guioptions-=r " 隐藏右侧滚动条
042
"set guioptions-=b " 隐藏底部滚动条
043
"set showtabline=0 " 隐藏Tab栏
044
endif
045
046
set writebackup " 设置无备份文件
047
set nobackup
048
set autochdir " 设定文件浏览器目录为当前目录
049
"set nowrap " 设置不自动换行
050
set foldmethod=syntax " 选择代码折叠类型
051
set foldlevel=100 " 禁止自动折叠
052
053
" 每行超过80个的字符用下划线标示
054
au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/
055
056
057
" 编码设置
058
"set encoding=utf-8
059
set fileencodings=utf-8,cp936,gbk,gb18030,big5,latin1
060
061
062
" For Haskell
063
:let hs_highlight_delimiters=1 " 高亮定界符
064
:let hs_highlight_boolean=1 " 把True和False识别为关键字
065
:let hs_highlight_types=1 " 把基本类型的名字识别为关键字
066
:let hs_highlight_more_types=1 " 把更多常用类型识别为关键字
067
:let hs_highlight_debug=1 " 高亮调试函数的名字
068
:let hs_allow_hash_operator=1 " 阻止把#高亮为错误
069
070
071
set laststatus=2 " 开启状态栏信息
072
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
073
074
" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]
075
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
076
077
078
079
" ######### 括号、引号、中括号等自动匹配 ######### "
080
081
:inoremap ( ()<ESC>i
082
083
:inoremap ) <c-r>=ClosePair(')')<CR>
084
085
:inoremap { {}<ESC>i
086
087
:inoremap } <c-r>=ClosePair('}')<CR>
088
089
:inoremap [ []<ESC>i
090
091
:inoremap ] <c-r>=ClosePair(']')<CR>
092
093
":inoremap < <><ESC>i
094
095
":inoremap > <c-r>=ClosePair('>')<CR>
096
097
:inoremap " ""<ESC>i
098
099
:inoremap ' ''<ESC>i
100
101
:inoremap ` ``<ESC>i
102
103
function ClosePair(char)
104
if getline('.')[col('.') - 1] == a:char
105
return "\<Right>"
106
else
107
return a:char
108
endif
109
endf
110
111
112
113
114
" ######### 自定义快捷键 ######### "
115
116
" Ctrl + K 将光标移到上一行的末尾
117
imap <ESC>kA
118
119
" Ctrl + L 将光标移到行尾
120
imap <ESC>A
121
122
" Ctrl + H 将光标移到行首
123
imap <ESC>I
124
125
" Ctrl + Z 取代ESC模式键
126
:inoremap <ESC>
127
128
" Ctrl + S 保存文件
129
map <ESC>:w<CR>
130
imap <ESC>:w<CR>a
131
vmap <ESC>:w<CR>
132
133
" Ctrl + E 一步加载语法模板和作者、时间信息 [非插入模式]
134
map <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
135
vmap <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
136
137
" Ctrl + E 在当前行添加C语言行注释 [插入模式]
138
imap /* */<ESC>hhi
139
140
141
142
143
144
" ######### 第三方插件 ######### "
145
146
" WinManager 直接输入 wm 命令即可开启文件浏览窗口
147
let g:winManagerWindowLayout='FileExplorer'
148
nmap wm :WMToggle<cr>
149
150
" MiniBufExplorer 多个文件切换 可使用鼠标双击相应文件名进行切换
151
let g:miniBufExplMapWindowNavVim=1
152
let g:miniBufExplMapWindowNavArrows=1
153
let g:miniBufExplMapCTabSwitchBufs=1
154
let g:miniBufExplModSelTarget=1
155
156
" TagList 键入:Tlist开启
157
let Tlist_Show_One_File=1 " 只显示当前文件的tags
158
let Tlist_Exit_OnlyWindow=1 " 如果Taglist窗口是最后一个窗口则退出Vim
159
let Tlist_Use_Right_Window=1 " 在右侧窗口中显示
160
161
" ctags
162
" --先在项目顶层目录执行ctags -R,然后打开源文件,在命令模式中执行如:set tags=../../tags
163
" --这样在函数名上按 <C-]> 即可转到函数定义,按 <C-T> 可以返回调用地址
164
" --如果长时间需要在该目录工作,也可以将tags路径写入配置文件
165
166
"set tags+=C:\Develop\MinGW\include\tags " For C/C++
167
"set tags+=C:\Develop\GTK\include\tags " For GTK+
168
"set tags+=C:\Develop\Lua\lua\tags " For Lua
169
"set tags+=G:\Cygwin\usr\include\tags " For Cygwin
170
171
" TxtBrowser 高亮TXT文本文件
172
au BufRead,BufNewFile *.txt setlocal ft=txt
173
174
" fencview 自动编码识别 :FencView 查看文件编码和更改文件编码
175
let g:fencview_autodetect=1
176
177
" Load_Template 根据文件后缀自动加载模板,使用:LoadTemplate呼出
178
let g:template_path='D:\Apps\Gvim\vimfiles\template\'
179
180
" NERD_commenter && authorinfo 自动添加作者、时间等信息,使用:AuthorInfoDetect呼出
181
let g:vimrc_author='Ruchee'
182
let g:vimrc_email='my@ruchee.com'
183
let g:vimrc_homepage='http://www.ruchee.com'
184
185
186
187
188
189
" ######### 一键保存和编译 ######### "
190
" ######### 如此处没有配置你需要的编程语言,请参照示例自行配置,很简单的
191
192
" 编译C源文件
193
func! CompileGcc()
194
exec "w"
195
let compilecmd="!gcc -Wall -pedantic -std=c99 "
196
let compileflag="-o %<"
197
exec compilecmd." % ".compileflag
198
endfunc
199
200
" 编译C++源文件
201
func! CompileCpp()
202
exec "w"
203
let compilecmd="!g++ -Wall -pedantic -std=c++98 "
204
let compileflag="-o %<"
205
exec compilecmd." % ".compileflag
206
endfunc
207
208
" 编译Java源文件
209
func! CompileJava()
210
exec "w"
211
exec "!javac %"
212
endfunc
213
214
" 编译Haskell源文件
215
func! CompileHaskell()
216
exec "w"
217
let compilecmd="!ghc --make "
218
let compileflag="-o %<"
219
exec compilecmd." % ".compileflag
220
endfunc
221
222
" 运行Lua源文件
223
func! RunLua()
224
exec "w"
225
exec "!lua %"
226
endfunc
227
228
" 运行Perl源文件
229
func! RunPerl()
230
exec "w"
231
exec "!perl %"
232
endfunc
233
234
" 运行Python源文件
235
func! RunPython()
236
exec "w"
237
exec "!python %"
238
endfunc
239
240
" 运行Ruby源文件
241
func! RunRuby()
242
exec "w"
243
exec "!ruby %"
244
endfunc
245
246
247
" 根据文件类型自动选择相应的编译函数
248
func! CompileCode()
249
exec "w"
250
if &filetype == "c"
251
exec "call CompileGcc()"
252
elseif &filetype == "cpp"
253
exec "call CompileCpp()"
254
elseif &filetype == "java"
255
exec "call CompileJava()"
256
elseif &filetype == "haskell"
257
exec "call CompileHaskell()"
258
elseif &filetype == "lua"
259
exec "call RunLua()"
260
elseif &filetype == "perl"
261
exec "call RunPerl()"
262
elseif &filetype == "python"
263
exec "call RunPython()"
264
elseif &filetype == "ruby"
265
exec "call RunRuby()"
266
endif
267
endfunc
268
269
" 运行可执行文件
func! RunResult()
exec "w"
if &filetype == "c"
exec "! %<"
elseif &filetype == "cpp"
exec "! %<"
elseif &filetype == "java"
exec "!java %<"
elseif &filetype == "haskell"
exec "! %<"
elseif &filetype == "lua"
exec "!lua %<.lua"
elseif &filetype == "perl"
exec "!perl %<.pl"
elseif &filetype == "python"
exec "!python %<.py"
elseif &filetype == "ruby"
exec "!ruby %<.rb"
endif
endfunc
" Ctrl + C 一键保存、编译
map :call CompileCode()<CR>
imap <ESC>:call CompileCode()<CR>
vmap <ESC>:call CompileCode()<CR>
" Ctrl + R 一键保存、运行
map :call RunResult()<CR>
imap <ESC>:call RunResult()<CR>
vmap <ESC>:call RunResult()<CR>