-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
371 lines (333 loc) · 10.2 KB
/
vimrc
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
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
366
367
368
369
370
371
"gvim setting
"colorscheme desert
"colorscheme ir_black
"set guifont=mingliu:h12
" 字典自動翻譯
set keywordprg=~/bin/ydict
set complete-=k complete+=k
" 設定 vim 編輯預設備份目錄, 必須先 mkdir ~/vi_backup/
set backupdir=~/vi_backup/
set backup
" set php pear path
set path+=/usr/share/php
" set <leader>
let mapleader=","
" map <Leader>h :echo "Hello world."<CR>
"security
set nomodeline
" 游標移動後, 一樣可以用 backspace, del 等刪除動作
set bs=2
"移除 UTF-8 BOM
set nobomb
" 保留 BOM
"set bomb
set mouse=a
set paste
" 過長不要斷行
set nowrap
" 設定營幕能顯示多少就多少, 不要過長顯示 @
set display=lastline
" 設定最大寬度, 當一行過長時, 會自動換行 (0 是停用此功能)
set textwidth=0
" 搜尋到的字加 hilight
set hlsearch
set incsearch
" 忽略大小寫, 都可以搜尋到
"set ignorecase
" terminal title 會設為 filename
set title
set runtimepath=~/.vim,$VIMRUNTIME
set history=50
filetype on
set number
set cindent
set autoindent
"set smartindent
" \t 會以 2個空格代替
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
" :sp 開檔時, 上面會列出所有檔案
set wildmenu
" 可以用 {{{ }}} 縮排 Folded
set foldmethod=marker
" vim 支援 256色
set t_Co=256
" html indent 支援在 *.php
filetype indent on
filetype plugin indent on " Enable filetype-specific indenting and plugins
" retab
set list
set listchars=tab:->,trail:.
" {{{ syntax highlight
syntax on
":highlight 可以看到所有的顏色
" 顏色 Templates
" /usr/share/vim/vim70/colors/desert.vim
"colorscheme default
colorscheme desert
"colorscheme darkblue
"hi Comment ctermbg=black ctermfg=darkcyan
hi Comment term=standout cterm=bold ctermfg=0
hi Search term=reverse ctermbg=3 ctermfg=0
hi Folded ctermbg=black ctermfg=darkcyan
hi Cursor ctermbg=Gray ctermfg=Blue
"hi Visual ctermbg=yellow ctermfg=blue
hi clear SpellBad
hi SpellBad term=underline cterm=underline ctermfg=red
"highlight Normal ctermbg=black ctermfg=white
"set background=light
" }}}
" {{{ 下面出現一列 bar.
set laststatus=2
set statusline=%4*%<\ %1*[%F]
set statusline+=%4*\ %5*[%{&encoding}, " encoding
"set statusline+=%{&fileformat}]%m " file format
set statusline+=%{&fileformat}%{\"\".((exists(\"+bomb\")\ &&\ &bomb)?\",BOM\":\"\").\"\"}]%m " file format & bomb detect
set statusline+=%4*%=\ %6*%y%4*\ %3*%l%4*,\ %3*%c%4*\ \<\ %2*%P%4*\ \>
highlight User1 ctermfg=red
highlight User2 term=underline cterm=underline ctermfg=green
highlight User3 term=underline cterm=underline ctermfg=yellow
highlight User4 term=underline cterm=underline ctermfg=white
highlight User5 ctermfg=cyan
highlight User6 ctermfg=white
"set ls=2
"set statusline=%<%f\ %m%=\ %h%r\ %-19([%p%%]\ %3l,%02c%03V%)%y
"highlight StatusLine term=bold,reverse cterm=bold,reverse
""highlight StatusLine ctermfg=2 ctermbg=0
""highlight StatusLine ctermfg=blue ctermbg=white
" }}}
" {{{ 像 ultraedit 一樣有一列的顏色
" Line highlight
set cursorline
" Column highlight
" set cursorcolumn
"highlight CursorLine cterm=none ctermbg=blue
highlight CursorLine cterm=bold ctermbg=4
" insert 的時後, 將 CursorLine 移除
au InsertEnter * set nocul
au InsertLeave * set cul
" }}}
" {{{ UTF-8 Big5 Setting
" 檔案存檔會存成utf-8編碼
" "set fileencoding=utf-8
" "
" " 以下四個設下去. vim 編出來都是 utf-8 編碼的.
"set fileencoding=utf-8
"set fileencodings=big5,utf-8
"set termencoding=utf-8
"設定自動轉換為 UTF-8 編碼
" vim 新開的檔案預設是 utf-8 編碼(寫檔)
set fileencoding=utf-8
" vim 新開的檔案預設是 utf-8 編碼(讀檔)
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
" 內部在用的encode(vim 內部在用的 encode)
set encoding=utf8
set tenc=utf8
" 使用 <F12> 來將文字編碼轉換成 Big5
map <F12> :set tenc=big5<cr>
" vim 啟動後,是使用 utf-8 編碼
" 所有可能的編碼
" set termencoding=big5
" 當 Terminal.app 的 Display > encoding 是設成 Big5-hkscs,也就是說 terminal
" 會把鍵盤的輸入以 big5 編碼方式送到 vim 時,vim 需要有這個設定,才會將 big5 的輸入
" 轉成上面設定的 utf-8 編碼。如果你的 Terminal.app 是用 utf-8
" 編碼,則可忽略此項。
" }}}
" {{{ For PHP Hot Key
" Map ; to run PHP parser check
"noremap ; :!php -l %<CR>
" Map <CTRL>-P to run actual file with PHP CLI
"noremap <C-P> :w!<CR>:!php %<CR>
" Map <CTRL>-M to search phpm for the function name currently under the cursor (insert mode only)
"inoremap <C-H> <ESC>:!phpm <C-R>=expand("<cword>")<CR><CR>
" Automatic close char mapping
"inoremap { {<CR>}<C-O>O
"inoremap [ []<LEFT>
"inoremap ( ()<LEFT>
"inoremap " ""<LEFT>
"inoremap ' ''<LEFT>
" }}}
" {{{ 直接按 F8 (Tlist, function list)
"source $HOME/.vim/phpdoc.vim
"ctags apt-get install exuberant-ctags
" }}}
" {{{ ctrl + n, ctrl + p(會自動把function列出) - php
set dictionary+=~/.vim/funclist.txt
" }}}
" {{{ vim 開 tab => imap <C-n> <Esc>:w<CR><Esc>
" NERDTree 關閉按 q 即可
nnoremap <silent> <F2> :w!<CR>
map <F2><F2><F2> <ESC>:wq!<CR>
nnoremap <silent> <F3> :q!<CR>
"map <F3> :set cursorline!<CR><Bar>:echo "Highlight active cursor line: " . strpart("OffOn", 3 * &cursorline, 3)<CR>
map <F4> :set spell!<CR><Bar>:echo "Spell check: " . strpart("OffOn", 3 * &spell, 3)<CR>
nnoremap <silent> <F5> :NERDTree<CR>
nnoremap <silent> <F8> :Tlist<CR>
nnoremap <silent> <F9> :set paste<CR>
"nnoremap <silent> <F6> :tabn<CR>
"nnoremap <C-n> <Esc>:tabnew<CR><Esc>:e
map <C-t>l <ESC>:tabnext<CR>
map <C-t>h <ESC>:tabprev<CR>
map <C-t>n <ESC>:tabnew<CR>:NERDTree<CR>
map <C-t>c <ESC>:tabclose<CR>
map <C-t>0 <ESC>:tabfirst<CR>
map <C-t>$ <ESC>:tablast<CR>
map <C-t>q <ESC>:qall<CR>
":nmap <C-t> :tabnew<cr>
"map <C-t>n <ESC>:tabnew<CR><ESC>:e
":nmap <C-tab> :tabnext<cr>
"map <C-w> <ESC>:tabclose<CR>
" Visual ?? tab ? shif-tab ???
map <Tab> >>
map <S-Tab> <<
" ??MS???
vmap <C-c> "yy
vmap <C-x> "yd
"nmap <C-v> "yp
vmap <C-v> "yp
" vim -p filename1 filname2
" :tabe filename
" gt
" Ctrl-x Ctrl-o
" Ctrl+n 再打就有列表,
" Ctrl+n Ctrl+p 就可以開始打, 然後自動搜尋到 function
" :setlocal spell spelllang=en_gb
" ]s - move to next spelling error
" z= - spelling suggestion
" }}}
" {{{ 會自動到最後離開的位置
if has("autocmd")
autocmd BufRead *.txt set tw=78
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif
endif
" }}}
" {{{ save .vimrc, auto exec, .vimrc 如果存檔, 就會立刻實現
autocmd! bufwritepost .vimrc source %
" }}}
" {{{ 自動去除不必要的空白
" Remove trailing whitespaces
" map \ :%s/[ ]*$//g
map \ :%s/\s*$//g
" 存檔時自動移除結尾空白
autocmd FileType c,cpp,java,php,perl,python,ruby,sh autocmd BufWritePre :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
" 縮排 加 移除空白
map <f11> <esc>1G=G<cr><esc>:%s/\s*$//<cr><esc>:noh<cr>
"http://blog.bs2.to/post/EdwardLee/17961
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
function! RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
" }}}
" {{{ tab 直接往後退, 而且一直選取著.
" <s-v> + <tab> 或 <s-v> + <s-tab>
xmap <tab> >gv
xmap <s-tab> <gv
" }}}
" {{{ python indent
" 開啟 Python 檔案時自動用縮排來 Folding 最多三層
" 縮排跟 Tab 都設定為 4 個空白
" 在關鍵字上按下 K 會透過 ipython 去查詢使用說明
" 或是直接輸入 :Man list 這樣的指令
" 把上面那段 script 加到 .vimrc 裡面就可以使用了
function! s:python_custom()
function! s:man(keyword)
echo system('ipython -quick -c "help ' . a:keyword . '"')
endfunction
setlocal tabstop=4 expandtab shiftwidth=4
setlocal foldnestmax=2 foldmethod=indent foldcolumn=3 foldlevel=2
command! -nargs=1 Man call s:man(<f-args>)
cnoremap K viwy:Man <C-R>"<CR>
endfunction
if has("autocmd")
autocmd Filetype python call s:python_custom()
endif
" }}}
" {{{ Tab 顏色
highlight TabLine ctermbg=white ctermfg=black
highlight TabLineFill ctermbg=black
highlight TabLineSel ctermbg=blue ctermfg=white
"hi TabLineFill guifg=#90fff0 guibg=#2050d0 ctermfg=white ctermbg=lightblue
"hi TabLine guifg=#90fff0 guibg=#2050d0 ctermfg=black ctermbg=white
"hi TabLineSel guifg=#90fff0 guibg=#2050d0 ctermfg=white ctermbg=LightMagenta
" }}}
" {{{ 用於自動 load session (Tab)
" Session:
function! AutoLoadSession()
let g:sessionfile = getcwd() . "/Session.vim"
if (argc() == 0 && filereadable(g:sessionfile))
echohl WarningMsg
echo "Session file exists. Load this? (y/n): "
echohl None
while 1
let c = getchar()
if c == char2nr("y")
so Session.vim
return
elseif c == char2nr("n")
return
endif
endwhile
endif
endfunction
function! AutoSaveSession()
if exists(g:sessionfile)
exe "mks! " .
g:sessionfile
endif
endfunction
augroup AutoLoadSettion
au!
au VimEnter * call AutoLoadSession()
au VimLeave * call AutoSaveSession()
augroup END
" }}}
" {{{ for Bundle
filetype off
filetype plugin indent on " required!
set rtp+=~/.workenv/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
Bundle 'taglist.vim'
Bundle 'SuperTab'
" Bundle 'vimwiki'
Bundle 'winmanager'
Bundle 'bufexplorer.zip'
Bundle 'The-NERD-tree'
Bundle 'matrix.vim--Yang'
Bundle 'FencView.vim'
Bundle 'Conque-Shell'
" Bundle 'Vimpress'
" Bundle 'Markdown'
" Bundle 'LaTeX-Suite-aka-Vim-LaTeX'
Bundle 'c.vim'
Bundle 'snipMate'
Bundle 'ack.vim'
" non github repos
Bundle 'git://git.wincent.com/command-t.git'
" Brief help
" :BundleList - list configured bundles
" :BundleInstall(!) - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles
" }}}