-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
405 lines (356 loc) · 11.4 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
set nocompatible
" {{{ Vundle
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Plugin 'gmarik/vundle'
" My Bundles here:
"
" original repos on github
Plugin 'tpope/vim-fugitive'
Plugin 'scrooloose/syntastic'
Plugin 'scrooloose/nerdcommenter'
"Plugin 'scrooloose/nerdtree'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'altercation/vim-colors-solarized'
Plugin 'spf13/vim-colors'
"Plugin 'flazz/vim-colorschemes'
Plugin 'tpope/vim-surround'
"Plugin 'Valloric/YouCompleteMe'
Plugin 'plasticboy/vim-markdown'
Plugin 'MultipleSearch', {'pinned': 1}
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tfnico/vim-gradle'
"Plugin 'msanders/snipmate.vim'
Plugin 'elixir-lang/vim-elixir'
Plugin '907th/vim-auto-save'
filetype plugin indent on " required!
"
" 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
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle command are not allowed..
" }}}
"
if &term == 'xterm' || &term == 'screen-bce'
set t_Co=256 " Enable 256 colors to stop the CSApprox warning and make xterm vim shine
endif
scriptencoding utf-8
set modelines=0
set nomodeline
set tabstop=4
set nowrap
set shiftwidth=4
set textwidth=0
set cinkeys-=0#
set indentkeys-=0#
set tags=./TAGS,tags;/
set noequalalways
set formatoptions+=crol " Add comment leader before newlines (cro). Don't auto-wrap lines already too long
set comments-=fb:- " Remove the so-called comment on hyphen
set shortmess+=filmnrxoOtT " abbrev. of messages (avoids 'hit enter')
set cinoptions+=t0,j1,L0
set nu
set ssop-=buffers
set scrolloff=3
set winminheight=0
set autoindent
set expandtab
set incsearch
set ignorecase
set smartcase
set nohlsearch
set ignorecase
set smartcase
set title
set mouse=a
set backspace=indent,eol,start
set secure
set wildignore=*.o,*.class,*.pyc
syntax on
"set background=dark
set foldmethod=marker
set grepprg=grep\ -nH\ $*\ /dev/null
let g:solarized_termtrans=0
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"
"let g:solarized_termcolors=128
let g:tex_flavor='latex'
let g:auto_save = 1
let g:auto_save_events = ['CursorHold', 'TextChanged', 'InsertLeave']
let g:auto_save_presave_hook = 'call Backup()'
let g:auto_save_silent = 1
let g:tar_secure = 1
function! Backup()
"let fileName = expand("%")
"call system('cp ' . fileName . ' ' . fileName . '.' . localtime())
"call system('ls -1 ' . fileName . '.* | head -n -10 | xargs rm')
endfunction
colorscheme solarized
let g:EasyMotion_leader_key = ','
let g:EasyMotion_keys = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ'
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_filetype_specific_completion_to_disable = ["lisp", "racket", "scheme"]
let g:syntastic_c_check_header = 1
let g:syntastic_c_config_file = '.syntastic_c_config'
let g:syntastic_java_javac_config_file = '.syntastic_javac_config'
let g:syntastic_java_javac_autoload_maven_classpath = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
" From snipMate
let g:SuperTabMappingForward = "<tab>"
"let NERDTreeIgnore=['\.o$', '\.sw[a-z]$', '\.hi$']
"let g:NERDTreeMapHelp=""
"let g:NERDTreeMapJumpNextSibling=""
"let g:NERDTreeMapJumpPrevSibling=""
"
let g:netrw_banner = 0
let g:netrw_fastbrowse = 2
set bdir=~/.vimbackup//,.
set dir=~/.vimbackup//,.
set linebreak
set display+=lastline
"{{{Key mappings
imap <up> <C-O>gk
imap <down> <C-O>gj
nmap <up> gk
nmap <down> gj
"XXX: to get this to work correctly, need to seek back for a surrounding char
"nmap di% %%d%
nnoremap j gj
nnoremap k gk
nnoremap Y y$
inoremap <C-_> </<C-X><C-O>
"call togglebg#map("<F5>")
vmap <up> gk
vmap <down> gj
map Q <Nop>
map <F1> <Nop>
imap <F1> <Nop>
inoremap vv <Esc>`^
inoremap <c-u> <c-g>u<c-u>
nmap . .`[
vnoremap <silent> . :normal .<CR>
inoremap { {}<Left>
inoremap {<Right> {
inoremap <expr> {<CR> strpart(getline('.'), col('.') - 1, 1) =~ '[^ ]' ? "{\<CR>": "{<CR>}<Esc>O"
inoremap {} {}
nmap zO zR
"map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
inoremap <expr> { strpart(getline('.'), col('.')-1, 1) == "}" ? "{\<Left>" :"{"
nmap <C-J> <C-W>j<C-W>_
nmap <C-K> <C-W>k<C-W>_
noremap <C-L> <C-W>l<C-W>\|
nmap <C-H> <C-W>h<C-W>\|
cmap Sh sh
set notimeout
set ttimeout
set ttimeoutlen=500
" Fix home and end keybindings for screen, particularly on mac
" - for some reason this fixes the arrow keys too. huh.
map [F $
imap [F $
map [H g0
imap [H g0
"}}}
set showmode " display the current mode
set cursorline " highlight current line
if has('cmdline_info')
set ruler " show the ruler
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " a ruler on steroids
set showcmd " show partial commands in status line and
" selected characters/lines in visual mode
endif
if has("cscope")
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add "cscope.out"
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
map g<C-]> :cs find 3 <C-R>=expand("<cword>")<CR><CR>
map g<C-\> :cs find 0 <C-R>=expand("<cword>")<CR><CR>
endif
let mapleader = ','
if has('statusline')
set laststatus=2
endif
"functions
function! SuperCleverTab()
" col('.') is the location of the character right *after* the cursor
" position.
" col('.') - 2 is the position of the character before the one you're
" on
let mystr = strpart(getline('.'), col('.') - 2 , 1)
if (mystr =~ '\s' || mystr == "")
return "\<Tab>"
else
return "\<C-N>"
endif
endfunction
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
" Remove trailing whitespaces and ^M chars
autocmd FileType perl,c,cpp,java,php,javascript,ruby,python,twig,xml,yaml,groovy autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
autocmd BufFilePost tarfile::* set ro
autocmd BufFilePost tarfile::*/* set ro
autocmd BufFilePost zipfile::* set ro
autocmd BufFilePost zipfile::*/* set ro
autocmd! BufWritePost *.rst silent ! rst2html <afile> 2>/dev/null > rst_out.html
autocmd FileType rst,markdown set spell
autocmd FileType rst,markdown setl cin!
autocmd FileType rst,markdown setl indentkeys=
imap <Tab> <C-R>=SuperCleverTab()<cr>
"inoremap <S-Tab> <C-P>
nnoremap <silent> <buffer> <Plug>SexpCloseParenthesis :call SlimvCloseForm()<CR>
"-------------------------------------------------------------------
" Close open parenthesis
" Taken from the Slimv plugin by Tamas Kovacs. Released in the
" public domain by the original author.
"-------------------------------------------------------------------
" Count the opening and closing parens or brackets to determine if they match
function! s:GetParenCount( lines )
let paren = 0
let inside_string = 0
let i = 0
while i < len( a:lines )
let inside_comment = 0
let j = 0
while j < len( a:lines[i] )
if inside_string
" We are inside a string, skip parens, wait for closing '"'
if a:lines[i][j] == '"'
let inside_string = 0
endif
elseif inside_comment
" We are inside a comment, skip parens, wait for end of line
else
" We are outside of strings and comments, now we shall count parens
if a:lines[i][j] == '"'
let inside_string = 1
endif
if a:lines[i][j] == ';'
let inside_comment = 1
endif
if a:lines[i][j] == '(' || a:lines[i][j] == '['
let paren = paren + 1
endif
if a:lines[i][j] == ')' || a:lines[i][j] == ']'
let paren = paren - 1
if paren < 0
" Oops, too many closing parens in the middle
return paren
endif
endif
endif
let j = j + 1
endwhile
let i = i + 1
endwhile
return paren
endfunction
function! LoadTemplate()
let template_name = expand("%:t")
let template_extension = expand("%:e")
let templates_directory = $HOME . "/.vim/templates"
let whole_name_template = templates_directory . "/" . template_name
let extension_template = templates_directory . "/" . template_extension
if filereadable(whole_name_template)
let original_template = whole_name_template
elseif filereadable(extension_template)
let original_template = extension_template
else
return
end
" Note: Use syscmd() macro to run arbitrary
" system commands for things like time of day, platform, etc.
let defs = {}
let defs['FILE_BASENAME'] = expand("%:t:r")
let defs['USER'] = $USER
let m4_args = ""
for [k,v] in items(defs)
let m4_args = m4_args . " -D" . k . "=" . v
endfor
let tmp = tempname()
let _ = system("cat " . original_template . "| m4 " . m4_args . " >" . tmp)
silent! execute "0read " tmp
" Highlight %VAR% placeholders with the Todo colour group
syn match Todo "%\u\+%" containedIn=ALL
normal /START_HERE/
normal dw
endfunction
let s:bgfile = $HOME . "/.vimbg"
function! MySetBG(v)
if a:v == 0
set bg=dark
else
set bg=light
endif
call system("echo " . a:v . " > " . s:bgfile)
return a:v
endfunction
function! MyReadBG()
return system("cat " . s:bgfile)
endfunction
call MySetBG(MyReadBG())
function! MyToggleBG()
let v = MyReadBG()
echo v
echo 'MyToggleBG ' . v
if v == 0
call MySetBG(1)
else
call MySetBG(0)
endif
endfunction
"inoremap <F5> <C-O>:call MyToggleBG()<CR>
"nmap <F5> :call MyToggleBG()<CR>
" Close current top level form by adding the missing parens
function! SlimvCloseForm()
let l2 = line( '.' )
normal 99[(
let l1 = line( '.' )
let form = []
let l = l1
while l <= l2
call add( form, getline( l ) )
let l = l + 1
endwhile
let paren = s:GetParenCount( form )
if paren > 0
" Add missing parens
let lastline = getline( l2 )
while paren > 0
let lastline = lastline . ')'
let paren = paren - 1
endwhile
call setline( l2, lastline )
endif
normal %
endfunction
nmap <buffer> <LocalLeader>cp <Plug>SexpCloseParenthesis
imap <buffer> <C-X>0 <C-O><LocalLeader>cp
autocmd! BufNewFile * call LoadTemplate()
"Jump between %VAR% placeholders in Normal mode with
" <Ctrl-p>
nnoremap <c-p> /%\u.\{-1,}%<cr>c/%/e<cr>
"Jump between %VAR% placeholders in Insert mode with
" <Ctrl-p>
inoremap <c-p> <ESC>/%\u.\{-1,}%<cr>c/%/e<cr>
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif