-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.vimrc
More file actions
352 lines (277 loc) · 8.96 KB
/
.vimrc
File metadata and controls
352 lines (277 loc) · 8.96 KB
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
" This must be first, because it changes other options as a side effect.
set nocompatible
filetype off
" enable plugins
syntax on
filetype on
filetype plugin on
filetype plugin indent on
" turn backup off
set nobackup
set nowb
" font
set gfn=Monospace\ 10
" tab map
map <M-Right> :tabnext<CR>
map <M-Left> :tabprev<CR>
" set GUI
set guioptions-=T
set laststatus=2
set statusline=%F%m%r%h%w\ [%n]\ [%b=%B]\ [%l,%v][%p%%]
" Maximize the window
" au GUIEnter * simalt ~x
" show line number
set number
"No sound on errors.
set noerrorbells
set novisualbell
"Ignore case when searching
set ignorecase
set smartcase
set incsearch
set hlsearch
set magic " enable wildcard
" Highlight current line and column
set cul
" Folding
set foldenable
set shiftwidth=4
" Ctrl X, Ctrl V, Ctrl Y, Ctrl S
vnoremap <C-X> "+x
vnoremap <C-C> "+y
map <C-V> "+gP
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
" Map Y to do the same (well, almost) as the D command
map Y y$
" set <Leader>
let mapleader = ","
" Switch to current dir
map <leader>cd :cd %:p:h<cr>
" Select the content we just pasted
map <leader>vp `[v`]
" Lookup in manual
map K :Man <cword><CR>
map <leader>mm :Man <cword>
" man page of System calls
map <leader>ms :Man 2 <C-r><C-w><CR>
" man page of Library calls
map <leader>ml :Man 3 <C-r><C-w><CR>
" Lookup symbol with Ack
map <leader>a :tab split<CR>:Ack ""<Left><Left><Left>
map <leader>A :tab split<CR>:Ack <C-r><C-w><CR>
" Open a buffer as scratch board
map <leader>q :tabe ~/buffer<CR>
" Open history window
map <leader>h :<C-F>
" color current workd in red, green, blue, black, and cyan
map <leader>c1 :exe 'Highlight 1 ' . expand('<cword>')<CR>
map <leader>c2 :exe 'Highlight 2 ' . expand('<cword>')<CR>
map <leader>c3 :exe 'Highlight 3 ' . expand('<cword>')<CR>
map <leader>c4 :exe 'Highlight 4 ' . expand('<cword>')<CR>
map <leader>c5 :exe 'Highlight 6 ' . expand('<cword>')<CR>
" List and choose buffer window
map <leader>b :ls<cr>:b
"map <leader>bs :ls<CR>:sb
"map <leader>bh :ls<CR>:sb .h<Left><Left>
" Tag
map <leader>f :tag
" run Makefile and open error
map <leader>k :make \| cwindow<cr>
" make current window the only window
map <leader>o :only<cr>
" open Taglist window
map <leader>c :Tlist<cr>
" show the quickfix window after executing any cmd contains grep
autocmd QuickFixCmdPost *grep* cwindow
" search using grep and show results in Quickfix
map <leader>g :vimgrep <cword> **/*.tex **/*.c **/*.cc **/*.h **/*.py<CR>
" open NERDTree window
map <leader>tt :NERDTreeToggle<cr>
map <leader>tf :NERDTreeFind<cr>
function! ToggleSpellChecking()
if !exists("g:checkspelling")
let g:checkspelling = 0
endif
if g:checkspelling == 0
setlocal spell spelllang=en_us
let g:checkspelling = 1
else
setlocal spell!
let g:checkspelling = 0
endif
endfunction
" spell check
map <leader>s :call ToggleSpellChecking()<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text options
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set noexpandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
map <leader>t2 :set shiftwidth=2 tabstop=2 softtabstop=2 expandtab<cr>
map <leader>t4 :set shiftwidth=4 tabstop=4 softtabstop=4 expandtab<cr>
map <leader>t8 :set shiftwidth=8 tabstop=8 softtabstop=8 noexpandtab<cr>
set smarttab
set lbr
set tw=79
""""""""""""""""""""""""""""""
" Indent
""""""""""""""""""""""""""""""
"Auto indent
set ai
"Smart indet
" set si
"C-style indenting
set cindent
"Wrap lines
set wrap
" the defaul on Mac is 0
set modelines=10
" function key
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
nnoremap <F8> :setl noai nocin nosi inde=<CR>
" no autoindentation
:nnoremap <F8> :setl noai nocin nosi inde=<CR>
map <F9> :set cinoptions=>8,(0,:0
" C++: set cinoptions=g1
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
autocmd BufNewFile,BufReadPost *.mkd set filetype=markdown
autocmd FileType gp setl textwidth=200
au BufRead,BufNewFile *.py set filetype=python
autocmd FileType python set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType c,cpp,h,java,sh,tex,html,ml setl foldmethod=syntax
autocmd FileType c,cpp,h,java,sh,tex,html,ml setl foldminlines=5
autocmd FileType c,cpp,h,java,sh,tex,html,ml setl foldlevel=3
autocmd FileType tex setl indentexpr=none
autocmd FileType gp setl textwidth=200
autocmd FileType gp set makeprg=gnuplot\ %
autocmd FileType c set noexpandtab|set tabstop=8|set shiftwidth=8
autocmd FileType c set cinoptions=>8,(0,:0
"autocmd FileType cc,cpp set expandtab|set tabstop=2|set shiftwidth=2
autocmd FileType html set tabstop=2|set shiftwidth=2|set expandtab|set textwidth=100
autocmd FileType tex set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType vim set tabstop=2|set shiftwidth=2|set noexpandtab
autocmd FileType sh set tabstop=2|set shiftwidth=2|set expandtab
autocmd FileType sh set iskeyword-=. " stop at . for word motions like w, e
"autocmd FileType markdown set tabstop=2|set shiftwidth=2|set expandtab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"My information
iab xdate <c-r>=strftime("%Y-%m-%d")<cr>
iab xtime <c-r>=strftime("%y-%m-%d %H:%M:%S")<cr>
iab xname Ming Chen
iab xchange <c-r>=strftime("%Y-%m-%d")<cr> Ming Chen <v.mingchen@gmail.com>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" For Tex
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:tex_flavor='latex'
autocmd FileType tex set makeprg=make\ pdf
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" For XML
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:xml_syntax_folding=1
" Taglist
let g:Tlist_Use_Right_Window=1
" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
function MkdFoldLevel(lineNo)
let thisline = getline(a:lineNo)
if ( thisline =~ '^#.*' )
let level = 0
while strpart(thisline, level, 1) == '#'
let level += 1
endwhile
let result = ">" . string(level)
return result
else
return "="
endif
endfunction
au FileType markdown set foldmethod=expr
au FileType markdown set foldexpr=MkdFoldLevel(v:lnum)
runtime! ftplugin/man.vim
if filereadable(expand("~/.local_vimrc"))
source ~/.local_vimrc
endif
" Associate .proto to google protocol buffer files
augroup filetype
au! BufRead,BufNewFile *.proto setfiletype proto
augroup end
" View RFC
if expand('%:t') =~? 'rfc\d\+'
"set readonly nomodifiable
setfiletype rfc
endif
" Display or remove unwanted whitespace with a script
function ShowSpaces(...)
let @/='\v(\s+$)|( +\ze\t)'
let oldhlsearch=&hlsearch
if !a:0
let &hlsearch=!&hlsearch
else
let &hlsearch=a:1
end
return oldhlsearch
endfunction
function TrimSpaces() range
let oldhlsearch=ShowSpaces(1)
execute a:firstline.",".a:lastline."substitute ///gec"
let &hlsearch=oldhlsearch
endfunction
" https://github.com/ciaranm/detectindent
let g:detectindent_preferred_expandtab = 0
let g:detectindent_preferred_indent = 8
command -bar -nargs=? ShowSpaces call ShowSpaces(<args>)
command -bar -nargs=0 -range=% TrimSpaces <line1>,<line2>call TrimSpaces()
nnoremap <F12> :ShowSpaces 1<CR>
nnoremap <S-F12> m`:TrimSpaces<CR>``
vnoremap <S-F12> :TrimSpaces<CR>
autocmd BufRead * DetectIndent
" use only simple char in path
set isfname=@,48-57,/,.,-,_,+,,,~
" make sure Ctrl-W can delete previous words not just inserted
set backspace=indent,eol,start
set clipboard=unnamed
" load OS-specific settings
let s:osvimrc = '~/profile/' . substitute(system("uname"), '\n', '.vimrc', '')
if filereadable(glob(s:osvimrc))
execute 'source ' . s:osvimrc
endif
" load host-specific settings
let s:hostvimrc = '~/profile/' . substitute(system("uname -n"), '\n', '.vimrc', '')
if filereadable(glob(s:hostvimrc))
execute 'source ' . s:hostvimrc
endif
if $TMUX != ''
set clipboard="
endif
" scheme, other cool colorscheme: wombat
colorscheme default
" highlight lines longer than 80
" From Damian Conway's "More Instantly Better Vim"
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
highlight Folded ctermbg=255
highlight Folded ctermfg=220
highlight SpellBad ctermfg=yellow
let g:UltiSnipsExpandTrigger = "<c-j>"
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger = "<c-J>"
" vimwiki
let wiki = {}
let wiki.path = '~/vimwiki/'
let wiki.nested_syntaxes = {'python': 'python', 'c++': 'cpp', 'go': 'go', 'java': 'java'}
let g:vimwiki_list = [wiki]