-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
360 lines (295 loc) · 8.66 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
set nocompatible
let mapleader=','
let s:at_google=filereadable(expand('~/.at_google'))
"""""""""""""""
" PLUGINS
"""""""""""""""
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'bling/vim-bufferline'
Plugin 'airblade/vim-gitgutter'
" ,g (Configured below)
Plugin 'tpope/vim-fugitive'
Plugin 'camelcasemotion'
" ,w
" ,e
" ,b
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" Ctrl-j to insert
" Ctrl-l to list
Plugin 'scrooloose/nerdcommenter'
" <leader>c<space> toggle comment
" <leader>cl to comment
Plugin 'jacoborus/tender.vim'
Plugin 'powerman/vim-plugin-AnsiEsc'
Plugin 'w0rp/ale'
Plugin 'aliou/bats.vim'
Plugin 'JamshedVesuna/vim-markdown-preview'
" <ctrl>p to preview.
Plugin 'noahfrederick/vim-skeleton'
Plugin 'udalov/kotlin-vim'
if !s:at_google
Plugin 'Valloric/YouCompleteMe'
" <leader>jd Jump to definition
Plugin 'fatih/vim-go'
" Add maktaba and codefmt to the runtimepath.
" (The latter must be installed before it can be used.)
Plugin 'google/vim-maktaba'
Plugin 'google/vim-codefmt'
" Also add Glaive, which is used to configure codefmt's maktaba flags. See
" `:help :Glaive` for usage.
Plugin 'google/vim-glaive'
endif
call vundle#end()
if s:at_google
source /usr/share/vim/google/google.vim
Glug youcompleteme-google
Glug ultisnips-google
Glug codefmt plugin[mappings]
Glug codefmt-google
Glug blaze plugin[mappings]='<leader>b'
let g:blazevim_notify_after_blaze=1
else
" the glaive#Install() should go after the "call vundle#end()"
call glaive#Install()
endif
augroup autoformat_settings
autocmd FileType bzl AutoFormatBuffer buildifier
if s:at_google
autocmd FileType go AutoFormatBuffer gofmt
autocmd FileType textpb AutoFormatBuffer text-proto-format
autocmd FileType gcl AutoFormatBuffer gclfmt
endif
augroup end
" Valloric/YouCompleteMe
nnoremap <leader>jd :YcmCompleter GoTo<CR>
" bling/vim-airline
set laststatus=2
let g:airline_theme='tender'
let g:airline_powerline_fonts=1
let g:airline_section_z='%4l/%L %3v'
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
" bling/vim-bufferline
let g:bufferline_echo=0
" airblade/vim-gitgutter
let g:gitgutter_signs=0
nnoremap <leader>g :GitGutterSignsToggle<CR>
" turn off gitgutter in status line
let g:airline#extensions#hunks#enabled=0
" noahfrederick/vim-skeleton
let g:skeleton_template_dir='~/.vim/closet'
let g:skeleton_find_template={}
function! g:skeleton_find_template.java(path)
return match(a:path, 'Test\.java$') != -1 ? 'test.java' : ''
endfunction
function! g:skeleton_find_template.go(path)
return match(a:path, 'Test\.go$') != -1 ? 'test.go' : ''
endfunction
let g:skeleton_replacements={}
let g:skeleton_replacements_java={}
let g:skeleton_replacements_ruby={}
" This function tries to find the relative path from a parent directory to the
" given path.
" Ex: find_subpath('src/foo/bar', ['src']) = 'foo/bar'
" - We find 'src'
" find_subpath('src/foo/bar', ['src', 'foo']) = 'bar'
" - We find 'foo' first
" find_subpath('src/foo/bar', ['foo/bar', 'src']) = '.'
" - We find 'foo/bar' first
" find_subpath('src/foo/bar', ['parent']) = ''
" - We don't find 'parent'
function! s:find_subpath(path, parents)
let l:idx=-1
for parent in a:parents
let l:parent_idx=stridx(a:path,l:parent)
if l:parent_idx != -1
let l:idx=max([stridx(a:path,l:parent) + len(l:parent), l:idx])
endif
endfor
if l:idx == -1
return ''
else
let l:subpath=a:path[l:idx + 1:]
if len(l:subpath) == 0
return '.'
else
return l:subpath
endif
endif
endfunction
" Returns true is the given path is absolute
" Returns false if it is not
function! s:is_absolute(path)
return stridx(a:path, getcwd()) == 0
endfunction
" expand('%:p') doesn't work for new files if their parent directories don't
" exist.
function! s:absolute(path)
let l:path=fnamemodify(a:path, ':p')
" strip trailing / that we may have just added
let l:path=substitute(l:path, '/$', '', '')
return s:is_absolute(l:path) ? l:path : getcwd() . '/' . l:path
endfunction
function! g:skeleton_replacements.INCLUDEGUARD()
let l:guard=toupper(expand('%:t:r')) . '_H'
let l:path=s:absolute(expand('%:h'))
let l:subpath=s:find_subpath(l:path, ['src'])
if len(l:subpath) != 0 && l:subpath != '.'
let l:subpath=toupper(substitute(l:subpath, '/', '_', 'g'))
let l:guard=l:subpath . '_' . l:guard
endif
return l:guard
endfunction
function! g:skeleton_replacements.DATE()
return strftime('%B %-d, %Y')
endfunction
function! g:skeleton_replacements_java.PACKAGE()
let l:path=s:absolute(expand('%:h'))
let l:subpath=s:find_subpath(l:path, ['src', 'java'])
if len(l:subpath) == 0 || l:subpath == '.'
return ''
else
return 'package ' . substitute(l:subpath, '/', '.', 'g') . ';
'
endif
endfunction
function! g:skeleton_replacements_ruby.CLASSNAME()
let l:name=expand('%:t:r')
" \v: Every ASCII character not A-Z,a-z,0-9,_ have their special meanings
" \u: Uppercase
let l:name = substitute(l:name, '\v_(\w+)', '\u\1', 'g')
" \<: start of word
return substitute(l:name, '\<.', '\u&', '')
endfunction
" SirVer/ultisnips
let g:UltiSnipsExpandTrigger='<c-j>'
let g:UltiSnipsListSnippets='<c-l>'
" scrooloose/nerdcommenter
let g:NERDDefaultAlign='left'
let g:NERDCustomDelimiters={'textpb': {'left': '#'}}
" w0rp/ale
let g:airline#extensions#ale#enabled = 1
if s:at_google
" Google has its own linters, and ale gets _really_ slow on these languages.
let g:ale_linters = {
\ 'cpp': [],
\ 'python': [],
\ 'java': [],
\ 'javascript': [],
\ 'typescript': [],
\}
endif
" JamshedVesuna/vim-markdown-preview
" pip install grip
let vim_markdown_preview_github=1
"""""""""""""""
" GENERAL
"""""""""""""""
filetype plugin indent on
syntax on
let g:is_bash = 1
if has("termguicolors")
set termguicolors
end
colorscheme tender
set backspace=indent,eol,start
set hidden "hide buffers
set rnu "relative line numbers
set nu "except for the '0' line
set showmatch "matching brackets
set showcmd
set wildmenu
set wildmode=list:longest
nnoremap ; :
vnoremap ; :
" If you forget to use sudoedit.
cmap w!! w !sudo tee %
nnoremap <leader>l :ls<CR>:b
"""""""""""""""
" NAVIGATION
"""""""""""""""
nnoremap j gj
nnoremap k gk
nnoremap g: g;
noremap <left> <nop>
noremap <right> <nop>
noremap <up> <nop>
noremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
"""""""""""""""
" HIGHLIGHT
"""""""""""""""
set hlsearch "search options
set ignorecase
set smartcase
set incsearch
noremap / /\v
noremap ? ?\v
cnoremap s/ s/\v
" Highlight whole words that match the one under the cursor
nnoremap <leader>h :let @/='\V\<<C-r><C-a>\>'<CR>:set hls<CR>
" Highlight text that matches the visual selection
vnoremap <leader>h y:let @/='\V<C-r>"'<CR>:set hls<CR>
nnoremap <leader><space> :nohls<CR>
augroup highlight
au!
" highlight long lines (81st character by default)
au BufEnter,WinEnter *
\ if &textwidth
\| let w:m1=matchadd('ErrorMsg', '\%' . (&textwidth + 1) . 'v.')
\|endif
au BufLeave *
\ if exists('w:m1')
\| call matchdelete(w:m1)
\| unlet w:m1
\|endif
" trailing whitespace
au BufEnter,WinEnter * let w:m2=matchadd('ErrorMsg', '\s\+$')
augroup END
"""""""""""""""
" SUBSTITUTE
"""""""""""""""
set gdefault
map <leader>s <leader>h:%s#<C-r>/##<left>
"""""""""""""""
" FORMATTING
"""""""""""""""
set textwidth=80
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
" j = Remove comment leader when joining
" r = Add comment leader automatically
" o = Add comment leader automatically when entering insert mode
set formatoptions+=jro
" t = Auto-wrap text using textwidth
set formatoptions-=t
""""""""""
" UNDO "
""""""""""
if !isdirectory($HOME."/.vim/undo")
call mkdir($HOME."/.vim/undo", 0700)
endif
set undodir=~/.vim/undo
set undofile