流量统计:
Rixu Blog (日需博客)
日需博客,每日必需来踩踩哦..
posts - 108,comments - 54,trackbacks - 0

非常优秀的vimrc设置。反正我很喜欢

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
" An example for a vimrc file.
"
" Maintainer: a18ccms <a18ccms@gmail.com>
" Last change: 2010 03 12
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
 
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
 
set history=50   " keep 50 lines of command line history
set showcmd   " display incomplete commands
 
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
 
" Don't use Ex mode, use Q for formatting
map Q gq
 
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
\ | wincmd p | diffthis
 
set guioptions-=T
 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设定默认解码
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
language message zh_CN.utf-8
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"set font
"set guifont=Nsimsun
 
"设置窗口大小
set lines=35
set columns=120
 
" 不要使用vi的键盘模式,而是vim自己的
"set nocompatible
 
" 在处理未保存或只读文件的时候,弹出确认
set confirm
 
" 与windows共享剪贴板
set clipboard+=unnamed
 
" 侦测文件类型
filetype on
 
" 载入文件类型插件
filetype plugin on
 
" 为特定文件类型载入相关缩进文件
filetype indent on
 
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
 
" 语法高亮
syntax on
 
" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
 
" 状态行颜色
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要备份文件(根据自己需要取舍)
set nobackup
 
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
 
" 字符间插入的像素行数目
set linespace=0
 
" 增强模式中的命令行自动完成操作
set wildmenu
 
" 在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
 
" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2
 
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
 
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
 
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
 
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
 
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
 
" 不让vim发出讨厌的滴滴声
set noerrorbells
 
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮显示匹配的括号
set showmatch
 
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5
 
" 在搜索的时候忽略大小写
set ignorecase
 
" 高亮被搜索的句子(phrases)
set hlsearch
 
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
 
" 输入:set list命令是应该显示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
 
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
 
" 不要闪烁
set novisualbell
 
" 我的状态行显示的内容(包括文件类型和解码)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
 
" 总是显示状态行
set laststatus=2
 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动格式化
set formatoptions=tcrqn
 
" 继承前一行的缩进方式,特别适用于多行注释
set autoindent
 
" 为C程序提供自动缩进
set smartindent
 
" 使用C样式的缩进
set cindent
 
" 制表符为4
set tabstop=4
 
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
 
" 不要用空格代替制表符
set noexpandtab
 
" 不要换行
set nowrap
 
" 在行和段开始处使用制表符
set smarttab
 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
 
if has("autocmd")
   autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
   autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
   autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o
   autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
   autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
   autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$") |
      \   exe "normal g`\"" |
      \ endif
endif " has("autocmd")
 
"设置Java代码的自动补全
au FileType java setlocal omnifunc=javacomplete#Complete
 
let mapleader = "."
"绑定自动补全的快捷键<C-X><C-O>到<leader>;
imap <leader>; <C-X><C-O>
 
"设定开关Taglist插件的快捷键为F4,可以在VIM的左侧栏列出函数列表等
map <F4> :Tlist<CR>
 
"设置程序的编译运行和调试的快捷键F5,F6,Ctrl-F5
map <F5> :call CompileRun()<CR>
map <C-F5> :call Debug()<CR>
map <F6> :call Run()<CR>
 
"设置代码格式化快捷键F3
map <F3> :call FormartSrc()<CR>
 
"设置tab操作的快捷键,绑定:tabnew到<leader>t,绑定:tabn, :tabp到<leader>n,
"<leader>p
map <leader>t :tabnew<CR>
map <leader>n :tabn<CR>
map <leader>p :tabp<CR>
 
"用cscope支持
"set csprg=d:\bin\cscope
 
"使用<leader>e打开当前文件同目录中的文件
if has("unix")
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
else
map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
endif
 
"定义CompileRun函数,用来调用进行编译和运行
func CompileRun()
exec "w"
"C程序
if &filetype == 'c'
exec "!del %<.exe"
exec "!gcc % -o %<.exe"
exec "!%<.exe"
elseif &filetype == 'cpp'
exec "!del %<.exe"
exec "!g++ % -o %<.exe"
exec "!%<.exe"
"Java程序
elseif &filetype == 'java'
exec "!del %<.class"
exec "!javac %"
exec "!java %<"
endif
endfunc
"结束定义CompileRun
 
"定义Run函数,用来调用进行编译和运行
func Run()
exec "w"
"C程序
if &filetype == 'c'
exec "!%<.exe"
elseif &filetype == 'cpp'
exec "!%<.exe"
"Java程序
elseif &filetype == 'java'
exec "!java %<"
endif
endfunc
"结束定义Run
 
"定义Debug函数,用来调试程序
func Debug()
exec "w"
"C程序
if &filetype == 'c'
exec "!del %<.exe"
exec "!gcc % -g -o %<.exe"
exec "!gdb %<.exe"
elseif &filetype == 'cpp'
exec "!del %<.exe"
exec "!g++ % -g -o %<.exe"
exec "!gdb %<.exe"
"Java程序
exec "!del %<.class"
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
endif
endfunc
"结束定义Debug
"定义FormartSrc()
func FormartSrc()
exec "w"
"C程序,Perl程序,Python程序
if &filetype == 'c'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'cpp'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'perl'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'py'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
"Java程序
elseif &filetype == 'java'
exec "!astyle --style=java --suffix=none %"
exec "e! %"
elseif &filetype == 'jsp'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'xml'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'html'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
 
elseif &filetype == 'htm'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
 
endif
endfunc
"结束定义FormartSrc
 
" 能够漂亮地显示.NFO文件
set encoding=utf-8
function! SetFileEncodings(encodings)
    let b:myfileencodingsbak=&fileencodings
    let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
    let &fileencodings=b:myfileencodingsbak
    unlet b:myfileencodingsbak
endfunction
 
au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single
au BufReadPost *.nfo call RestoreFileEncodings()
 
" 高亮显示普通txt文件(需要txt.vim脚本)
au BufRead,BufNewFile * setfiletype txt
 
" 用空格键来开关折叠
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
 
colo darkblue

文件下载: 点击下载

Logo
作者:Gezidan
出处:http://www.rixu.net    
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted on 2011-08-08 11:21 日需博客 阅读(1490) 评论(0)  编辑 收藏 引用 所属分类: Linux转载