1 "history
2 set history=700
3
4 "syntax highlight
5 syntax on
6
7 "enable filetype plugins
8 filetype plugin indent on
9 filetype plugin on
10 "
11 "Highlight from start of file
12 autocmd BufEnter * :syntax sync fromstart
13
14 let mapleader=","
15
16 " auto save files when focus is lost
17 "au FocusLost * :p
18
19 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
20 " => VIM user interface
21 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
22 " Set 7 lines to the cursor - when moving vertically using j/k
23 set so=7
24
25 set nocompatible " 关闭兼容模式
26
27 " Turn on the WiLd menu
28 set wildmenu
29
30 " Ignore compiled files
31 set wildignore=*.o,*~,*.pyc
32 set wildignore+=*/tmp/*,*.so,*.swp,*.zip,.DS_Store
33
34 "Always show current position
35 set ruler
36
37 " Height of the command bar
38 set cmdheight=2
39
40 " Configure backspace so it acts as it should act
41 set backspace=eol,start,indent
42 set whichwrap+=<,>,h,l
43
44 " Ignore case when searching
45 set ignorecase
46
47 " When searching try to be smart about cases
48 " 在设置ignorecase的情况下,如果输入的搜索模式中含有大写,
49 " 则并不忽略大小写
50 set smartcase
51
52 " Highlight search results
53 set hlsearch
54
55 " Makes search act like search in modern browsers
56 " 搜索时,就显示搜索结果
57 set incsearch
58
59 " Don't redraw while executing macros (good performance config)
60 " 延迟重绘
61 set lazyredraw
62
63 " For regular expressions turn magic on
64 " 使用正则时,除了$ . * ^以外的元字符都要加反斜线
65 set magic
66
67 if has("gui_running")
68 set guioptions-=T
69 set guioptions+=e
70 set guitablabel=%M\ %t
71 endif
72
73 " Show matching brackets when text indicator is over them
74 set showmatch
75
76 " How many tenths of a second to blink when matching brackets
77 set mat=2
78
79 " 打开自动缩,继承前一行的缩进方式,特别适用于多行注释
80 set autoindent
81
82 " 显示行号
83 set nu
84
85 " 显示命令
86 set showcmd
87
88 " 不使用swp文件
89 set noswapfile
90
91 " 关闭备份
92 set nobackup
93
94 " 增量式搜索
95 set incsearch
96
97 " 高亮搜索
98 set hlsearch
99
100 set nowb
101
102 " 在breakat字符处而不是最后一个字符处断行
103 set lbr
104
105 " 自动缩进
106 set ai
107
108 " 智能缩进
109 set si
110
111 " 当文件在外部被修改时,自动重新读取
112 set autoread
113
114 " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等
115 set mouse=a
116
117 " 隐藏右边滚动条
118 set guioptions-=R
119
120 " 正确地处理中文字符的折行和拼接
121 set formatoptions+=mM
122
123 " 文件UTF-8编码
124 set fileencodings=utf-8
125
126 " 切换粘贴模式
127 "set pastetoggle=<F10>
128 "set list
129 "set listchars=tab:?\ ,eol:?
130
131 " 设置缩进
132 set expandtab
133 set smarttab
134 set shiftwidth=4
135 set tabstop=4
136
137 " 设置移动
138 " 折行内移动
139 map j gj
140 map k gk
141
142 " Return to last edit position when opening files (You want this!)
143 autocmd BufReadPost *
144 \ if line("'\"") > 0 && line("'\"") <= line("$") |
145 \ exe "normal! g`\"" |
146 \ endif
147 " Remember info about open buffers on close
148 set viminfo^=%
149
150 " 设置状态栏
151 "总是显示状态栏
152 set laststatus=2
153
154 "状态栏格式
155 set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ Column:\ %3c\ %P
156
157 function! HasPaste()
158 if &paste
159 return 'PASTE MODE '
160 en
161 return ''
162 endfunction
163
164 " 自动完成括号和引号
165 inoremap ( ()<esc>:let leavechar=")"<cr>i
166 inoremap [ []<esc>:let leavechar="]"<cr>i
167 "inoremap { {}<esc>:let leavechar="}"<cr>i
168 inoremap {<cr> {<esc>o}<esc>:let leavechar="}"<cr>O
169 inoremap <leader>' ''<esc>:let leavechar="'"<cr>i
170 inoremap <leader>" ""<esc>:let leavechar='"'<cr>i
171 " 对于{还不适用
172 imap <C-l> <Esc>:exec "normal f" .leavechar<CR>a
173 " 给现有文字添加括号
174 vnoremap ( <Esc>`>a)<Esc>`<i(<Esc>))
175
176 """""""""""""""""""""""""""""""""""""""""""""""""
177 """"""""""""""""""""C && C++ programming"""""""""
178 """""""""""""""""""""""""""""""""""""""""""""""""
179 "打开C/C++风格的自动缩进
180 set cin
181 "自动设置目录为正在编辑的文件所在目录
182 set autochdir
183 "自动格式化
184 set formatoptions=tcrqn
185 "继承前一行的缩进方式
186 set autoindent
187 "为C程序提供自动缩进
188 set smartindent
189
190 "设置winmanager
191 "let g:winManagerWindowLayout='FileExplorer,Taglist'
192 "let g:winManagerWindowLayout="BufExplorer,FileExplorer|TagList"
193 "let g:NERDTree_title="[NERDTree]"
194 "function! NERDTree_Start()
195 " exe 'NERDTree'
196 " endfunction
197
198 "function! NERDTree_IsValid()
199 " return 1
200 " endfunction
201 let g:winManagerWindowLayout="TagList|FileExplorer,BufExplorer"
202 let g:winManagerWidth=25
203 "let g:bufExplorerMaxHeight=20
204 "let g:bufExplorerResize=0
205 "set autooopen ok
206 let g:AutoOpenWinManager=1
207 nmap <silent> <F8> :WMToggle<cr>
208 "设置file explorer
209 let g:explVertical=1
210 "let g:explWinSize=""
211 let g:explHideFiles='^\.,.*\.o$,.*\.class$,.*\.swp$,.*\.pyc$,.*\.swo$,\.DS_Store$'
212 nmap <C-W><C-F> :FirstExplorerWindow<cr>
213 nmap <C-W><C-B> :BottomExplorerWindow<cr>
214
215 "设置Taglist
216 let Tlist_Ctags_Cmd='D:\ctags58\ctags.exe'
217 let Tlist_Show_One_File=1
218 let Tlist_Use_Right_Window=1
219 let Tlist_Sort_Type="name"
220 "let Tlist_Process_File_Always=1
221 let Tlist_Exit_OnlyWindow=1
222 "let Tlist_Auto_Open=1
223 let Tlist_File_Fold_Auto_Close=1
224 "let Tlist_WinHeight=10
225 "let Tlist_WinWidth=35
226 "显示taglist菜单
227 let Tlist_Show_Menu=1
228 "nnoremap <silent> <F9> :TlistToggle<CR>
229
230
231 "设置cscope
232 if has("cscope")
233 set csprg=/usr/local/bin/cscope
234 set csto=0
235 set cst
236 set nocsverb
237 "add any database in current directory
238 if filereadable("cscope.out")
239 cs add cscope.out
240 "else add database pointed to by environment
241 elseif $CSCOPE_DB !=""
242 cs add $CSCOPE_DB
243 endif
244 set csverb
245 endif
246 "<C-@>s表示同时按住C和@ 再按下s
247 nmap <C-s> :cs find s <C-R>=expand("<cword>")<CR><CR>
248 nmap <C-g> :cs find g <C-R>=expand("<cword>")<CR><CR>
249 nmap <C-c> :cs find c <C-R>=expand("<cword>")<CR><CR>
250 nmap <C-t> :cs find t <C-R>=expand("<cword>")<CR><CR>
251 nmap <C-e> :cs find e <C-R>=expand("<cword>")<CR><CR>
252 nmap <C-f> :cs find f <C-R>=expand("<cfile>")<CR><CR>
253 nmap <C-i> :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
254 nmap <C-d> :cs find d <C-R>=expand("<cword>")<CR><CR>
255
256 "设置ctags
257 "map <F12> :call Do_CsTag()<CR>
258
259 "function Do_CsTag()
260 " if(executable('cscope')&&has('cscope'))
261 " call system('find . -name "*.h" -o -name "*.c" -o -name "*.cpp">cscope.files')
262 " call system('cscope -bq')
263 " if filereadable("cscope.out")
264 " call system('cs add cscope.out')
265 " endif
266 " endif
267 " if(executable('ctags'))
268 " call system('ctags -R --c-types=+p --fields=+S *')
269 " endif
270 "endf
271
272 set tags=Z:/root/program/tags
273 " ^z快速进入shell
274 nmap <C-Z> :shell<cr>
275 " 在文件名上按gf时,在新的tab中打开
276 " map gf :tabnew <cfile><cr>
277 " Tab和Shift-Tab缩进
278 nmap <tab> v>
279 nmap <s-tab> v<
280 vmap <tab> >gv
281 vmap <s-tab> <gv
282
283 " CTRL-C are Copy
284 "vnoremap <C-C> "+y
285 " CTRL-V are Paste
286 "map <C-V> "+gP
287 "cmap <C-V> <C-R>+
288 "imap <C-V> <C-R>+
289
290 " strip all trailing whitespace in the current file
291 nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
292 " reselect the text that was just pasted
293 nnoremap <leader>V V`]
294 " 水平分割窗口
295 nnoremap <leader>s <C-w>s
296 " 垂直分割窗口
297 nnoremap <leader>v <C-w>v
298 " ack
299 nnoremap <leader>a :Ack
300 " highlight cursor column
301 nnoremap <leader>lc :set cursorcolumn!<CR>
302 " highlight cursor line
303 nnoremap <leader>ll :set cursorline!<CR>
304
305 nnoremap <leader>ms :set colorcolumn=80<CR>
306 nnoremap <leader>mh :set colorcolumn=0<CR>
307
308 " toggle between one window and multi-window (ZoomWin plugin)
309 map <leader>z <C-w>o
310
311 " 窗口区域切换,Ctrl+jkhl 来切换
312 map <C-j> <C-W>j
313 map <C-k> <C-W>k
314 map <C-h> <C-W>h
315 map <C-l> <C-W>l
316 " 窗口区域切换,Ctrl+↑↓←→ 来切换
317 imap <silent> <C-left> <esc><C-W><left>
318 vmap <silent> <C-left> <esc><C-W><left>
319 nmap <silent> <C-left> <C-W><left>
320 imap <silent> <C-right> <esc><C-W><right>
321 vmap <silent> <C-right> <esc><C-W><right>
322 nmap <silent> <C-right> <C-W><right>
323 imap <silent> <C-up> <esc><C-W><up>
324 vmap <silent> <C-up> <esc><C-W><up>
325 nmap <silent> <C-up> <C-W><up>
326 imap <silent> <C-down> <esc><C-W><down>
327 vmap <silent> <C-down> <esc><C-W><down>
328 nmap <silent> <C-down> <C-W><down>
329
330 " AutoComplPop
331 "let g:AutoComplPop_Behavior = {
332 "\ 'c': [ {'command' : "\<C-x>\<C-o>",
333 "\ 'pattern' : ".",
334 "\ 'repeat' : 0}
335 "\ ]
336 "\}
337 "let g:acp_behaviorSnipmateLength=1
338
339 " ctrlp
340 set runtimepath^=~/.vim/bundle/ctrlp
341 let g:ctrlp_working_path_mode = 2
342 let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
343
344 set t_Co=256
345 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }
346 colorscheme desert
347
348 "取消查找高亮
349 map <F2> :nohlsearch<CR>
350 set cursorline
351 if has("win32")
352 set guifont=Courier_New:h12:cANSI
353 au GUIEnter * simalt ~x
354 endif