-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
590 lines (495 loc) · 12.1 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
" __ __ _ _____ _________
" \ \ | |_| V __/ __|
" \ \| | | | | | | | [__
" [_] \___|_|_|_|_|_| \____|
" Execute the following command to bring the full power:
"
" :call VimrcSetUp()
" Encoding {{{
set encoding=utf-8
scriptencoding utf-8
" }}}
" Environment {{{
function! VimrcEnvironment()
let env = {}
let env.is_mac = has('mac')
let env.is_win = has('win32')
let user_dir = env.is_win
\ ? expand('$VIM/vimfiles')
\ : expand('~/.vim')
let env.path = {
\ 'user': user_dir,
\ 'plugins': user_dir . '/plugins',
\ 'plug_preset': user_dir . '/plug-preset.vim',
\ 'data': user_dir . '/data',
\ 'local_vimrc': user_dir . '/.vimrc_local',
\ 'tmp': user_dir . '/tmp',
\ 'undo': user_dir . '/data/undo',
\ 'vim_plug': user_dir . '/vim-plug',
\ }
return env
endfunction
let s:env = VimrcEnvironment()
" }}}
" Required plugins {{{
let s:plugins = [
\ 'AndrewRadev/linediff.vim',
\ 'Shougo/vimproc',
\ 'Vimjas/vim-python-pep8-indent',
\ 'andymass/vim-matchup',
\ 'cespare/vim-toml',
\ 'chaoren/vim-wordmotion',
\ 'cocopon/colorswatch.vim',
\ 'cocopon/iceberg.vim',
\ 'cocopon/inspecthi.vim',
\ 'cocopon/ntdcoco.vim',
\ 'cocopon/pgmnt.vim',
\ 'cocopon/shadeline.vim',
\ 'cocopon/snapbuffer.vim',
\ 'cocopon/vaffle.vim',
\ 'ctrlpvim/ctrlp.vim',
\ 'delphinus/vim-auto-cursorline',
\ 'editorconfig/editorconfig-vim',
\ 'flowtype/vim-flow',
\ 'iberianpig/tig-explorer.vim',
\ 'itchyny/thumbnail.vim',
\ 'jparise/vim-graphql',
\ 'junegunn/vim-easy-align',
\ 'kana/vim-textobj-indent',
\ 'kana/vim-textobj-user',
\ 'lambdalisue/gina.vim',
\ 'leafgarland/typescript-vim',
\ 'mattn/emmet-vim',
\ 'mattn/sonictemplate-vim',
\ 'mattn/vim-lsp-settings',
\ 'morhetz/gruvbox',
\ 'mxw/vim-jsx',
\ 'neovimhaskell/haskell-vim',
\ 'pangloss/vim-javascript',
\ 'prabirshrestha/asyncomplete-buffer.vim',
\ 'prabirshrestha/asyncomplete-file.vim',
\ 'prabirshrestha/asyncomplete-lsp.vim',
\ 'prabirshrestha/asyncomplete.vim',
\ 'prabirshrestha/vim-lsp',
\ 'prettier/vim-prettier',
\ 'previm/previm',
\ 'rking/ag.vim',
\ 'sophacles/vim-processing',
\ 'stephpy/vim-yaml',
\ 'thinca/vim-qfreplace',
\ 'thinca/vim-quickrun',
\ 'thinca/vim-ref',
\ 'thinca/vim-themis',
\ 'thinca/vim-zenspace',
\ 'tikhomirov/vim-glsl',
\ 'tomtom/tcomment_vim',
\ 'tpope/vim-markdown',
\ 'tpope/vim-surround',
\ 'tweekmonster/helpful.vim',
\ 'tyru/open-browser.vim',
\ 'w0ng/vim-hybrid',
\ 'w0rp/ale',
\ ]
let s:colorscheme = 'iceberg'
" }}}
" Setup {{{
function! VimrcSetUp()
call s:install_plugin_manager()
endfunction
" }}}
" Installation {{{
function! s:mkdir_if_needed(dir)
if isdirectory(a:dir)
return 0
endif
call mkdir(a:dir, 'p')
return 1
endfunction
function! s:install_plugins()
call s:mkdir_if_needed(s:env.path.plugins)
if exists(':PlugInstall')
PlugInstall
return 1
endif
return 0
endfunction
function! s:clone_repository(url, local_path)
if isdirectory(a:local_path)
return
endif
execute printf('!git clone %s %s', a:url, a:local_path)
endfunction
function! s:install_plugin_manager()
call s:mkdir_if_needed(s:env.path.user)
call s:mkdir_if_needed(s:env.path.data)
call s:clone_repository(
\ 'https://github.com/junegunn/vim-plug',
\ s:env.path.vim_plug . '/autoload')
call s:clone_repository(
\ 'https://github.com/cocopon/plug-preset.vim',
\ s:env.path.plug_preset)
if !s:activate_plugin_manager()
return 0
endif
if !s:install_plugins()
return 0
endif
echo 'Restart vim to finish the installation.'
return 1
endfunction
" }}}
" Activation {{{
function! s:load_plugin(path)
try
execute 'set runtimepath+=' . a:path
return 1
catch /:E117:/
" E117: Unknown function
return 0
endtry
endfunction
function! s:activate_plugins()
if !exists(':Plug')
" Plugin manager is not installed yet
return 0
endif
let command = exists(':PresetPlug')
\ ? 'PresetPlug'
\ : 'Plug'
for plugin in s:plugins
execute printf("%s '%s'", command, plugin)
endfor
return 1
endfunction
function! s:activate_plugin_manager_internal()
" Activate plugin manager
if !exists(':Plug')
execute 'set runtimepath+=' . s:env.path.vim_plug
endif
call plug#begin(s:env.path.plugins)
try
" Activate PresetPlug
if !exists(':PresetPlug')
execute 'set runtimepath+=' . s:env.path.plug_preset
endif
call plug_preset#init()
" Activate plugins
return s:activate_plugins()
finally
call plug#end()
filetype indent on
filetype plugin on
endtry
endfunction
function! s:activate_plugin_manager()
try
return s:activate_plugin_manager_internal()
catch /:E117:/
" E117: Unknown function
" Plugin manager is not installed yet
return 0
endtry
endfunction
" }}}
" Initialization {{{
call s:mkdir_if_needed(s:env.path.tmp)
call s:mkdir_if_needed(s:env.path.undo)
let s:plugins_activated = s:activate_plugin_manager()
" }}}
" Mappings {{{
" Turn off the IME when escaping from Insert mode
inoremap <silent> <ESC> <ESC>:<C-u>set iminsert=0<CR>
" Intuitive cursor movement in wrapped line
noremap j gj
noremap k gk
" Switch active window
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Emacs-like keybind
cnoremap <C-a> <Home>
cnoremap <C-b> <Left>
cnoremap <C-d> <Del>
cnoremap <C-e> <End>
cnoremap <C-f> <Right>
cnoremap <C-h> <Backspace>
cnoremap <C-k> <C-\>e getcmdpos() == 1 ? '' : getcmdline()[:getcmdpos() - 2]<CR>
inoremap <C-a> <Home>
inoremap <C-b> <Left>
inoremap <C-d> <Del>
inoremap <C-e> <End>
inoremap <C-f> <Right>
inoremap <C-h> <Backspace>
inoremap <C-k> <C-o>D
inoremap <C-n> <Down>
inoremap <C-p> <Up>
" Refer to history in command-line mode
cnoremap <C-p> <Up>
cnoremap <Up> <C-p>
cnoremap <C-n> <Down>
cnoremap <Down> <C-n>
" Open the parent directory, or the current directory if empty
nnoremap <silent> <C-u> :<C-u>call vaffle#init(expand('%'))<CR>
" Insert escaped '/' while inputting a search pattern
cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/'
" For JIS keyboard
inoremap <C-@> <Nop>
" For US keyboard
noremap ; :
" Clear hlsearch
nnoremap <silent> <Esc><Esc> :<C-u>set nopaste<CR>:nohlsearch<CR>:diffoff!<CR>
" Misc
nnoremap Y y$
nnoremap K <Nop>
" }}}
" File types {{{
augroup vimrc_filetype
autocmd!
autocmd BufNewFile,BufRead *.as setlocal filetype=javascript
autocmd BufNewFile,BufRead *.gradle setlocal filetype=groovy
autocmd BufNewFile,BufRead *.pde setlocal filetype=processing
autocmd BufNewFile,BufRead *.podspec setlocal filetype=ruby
autocmd BufNewFile,BufRead Podfile setlocal filetype=ruby
autocmd FileType gitcommit setlocal nocursorline spell spelllang=cjk,en
autocmd FileType text setlocal textwidth=0
autocmd FileType vim setlocal foldmethod=marker
augroup END
" }}}
" Terminal {{{
tnoremap <ESC><ESC> <C-\><C-n>
if exists('&termwinkey')
set termwinkey=<C-_>
endif
" }}}
" Misc {{{
set completeopt=menu,menuone,noinsert,noselect
set display=lastline
set grepprg=grep\ -nH
set mouse=a
set nrformats-=octal
set shortmess=acTI
set splitright
set virtualedit=block
set wildmenu
" Appearance
set ambiwidth=double
set background=dark
set cmdheight=2
set cursorline
set laststatus=2
set list
set listchars=eol:¬,tab:▸\
set number
set numberwidth=5
set showcmd
set showmatch
set wrap
" Backup
set nobackup
set noswapfile
let &undodir = s:env.path.undo
set undofile
" IME
set iminsert=0
set imsearch=-1
set noimcmdline
set noimdisable
" Indent
set autoindent
if exists('&breakindent')
set breakindent
endif
set noexpandtab
set nosmartindent
set shiftround
set shiftwidth=4
set tabstop=4
" Scroll
set scrolloff=8
set sidescroll=1
set sidescrolloff=16
" Search
set hlsearch
set ignorecase
set incsearch
set smartcase
set wrapscan
" }}}
" Plugins {{{
" netrw {{{
let g:netrw_altv = 1
let g:netrw_preview = 1
" }}}
if s:plugins_activated
" ag {{{
let g:ag_prg = 'ag --vimgrep --smart-case'
" }}}
" ale {{{
let g:ale_linters = {
\ 'javascript': ['eslint', 'flow'],
\ 'typescript': ['tsserver'],
\ }
let g:ale_open_list = 1
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_virtualtext_cursor = 1
" }}}
" asyncomplete.vim {{{
call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'allowlist': ['*'],
\ 'blocklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ }))
if !has('nvim')
autocmd User lsp_float_opened
\ call popup_setoptions(lsp#ui#vim#output#getpreviewwinid(), {
\ 'border': [0, 0, 0, 0],
\ 'padding': [0, 1, 0, 1],
\ })
end
" }}}
" ctrlp {{{
let g:ctrlp_cache_dir = s:env.path.data . '/ctrlp'
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](node_modules|\.git)$',
\ }
let g:ctrlp_map = ''
let g:ctrlp_match_window = 'bottom,order:ttb'
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<C-h>', '<BS>'],
\ 'PrtClear()': ['<C-k>'],
\ 'PrtCurLeft()': ['<C-b>', '<Left>'],
\ 'PrtCurRight()': ['<C-f>', '<Right>'],
\ 'PrtDelete()': ['<C-d>', '<Del>'],
\ 'PrtHistory(-1)': [],
\ 'PrtHistory(1)': [],
\ 'PrtSelectMove("j")': ['<C-n>', '<Down>'],
\ 'PrtSelectMove("k")': ['<C-p>', '<Up>'],
\ 'ToggleByFname()': [],
\ 'ToggleType(-1)': ['<C-Down>'],
\ 'ToggleType(1)': ['<C-Up>'],
\ }
let g:ctrlp_tilde_homedir = 1
nnoremap <C-g> :CtrlPMixed<CR>
" }}}
" flow {{
let g:flow#enable = 0
let g:flow#omnifunc = 0
" }}
" gina {{{
let g:gina#command#blame#use_default_mappings = 0
" }}}
" go {{{
let g:go_version_warning = 0
" }}}
" javascript {{{
let g:javascript_plugin_flow = 1
" }}}
" linediff {{{
let g:linediff_first_buffer_command = 'new'
let g:linediff_further_buffer_command = 'vertical new'
" }}}
" matchup {{{
let g:matchup_matchparen_offscreen = {
\ 'method': 'popup',
\ }
" }}}
" ntdcoco {{{
nmap <Bar> <Plug>(ntdcoco-toggle-cursor)
" }}}
" open-browser {{{
nmap gW <Plug>(openbrowser-open)
" }}}
" pgmnt {{{
let g:pgmnt_auto_source = 1
" }}}
" prettier
" {{{
let g:prettier#exec_cmd_async = 1
let g:prettier#quickfix_enabled = 0
" }}}
" quickrun {{{
let g:quickrun_config = {}
let g:quickrun_config['_'] = {
\ 'runner': 'vimproc',
\ 'runner/vimproc/updatetime': 40,
\ }
let g:quickrun_config['processing'] = {
\ 'command': 'processing-java',
\ 'exec': '%c --sketch=%s:p:h/ --output=' . s:env.path.tmp . '/processing --force --run',
\ }
" }}}
" ref {{{
let g:ref_cache_dir = s:env.path.data . '/ref'
" }}}
" shadeline {{{
let g:shadeline = {}
let g:shadeline.active = {
\ 'left': [
\ 'fname',
\ 'flags',
\ 'ShadelineItemGitBranch',
\ ],
\ 'right': [
\ '<',
\ ['ff', 'fenc', 'ft'],
\ 'ruler',
\ ],
\ }
let g:shadeline.inactive = {
\ 'left': [
\ 'fname',
\ 'flags',
\ ],
\ }
function! ShadelineItemGitBranch()
try
let name = gina#component#repo#branch()
return empty(name) ? '' : printf('(%s)', name)
catch /:E117:/
" E117: Unknown function
return ''
endtry
endfunction
" }}}
" sonictemplate {{{
let g:sonictemplate_vim_template_dir = s:env.path.plugins . '/sonictemplate-templates/template'
" }}}
" vaffle {{{
let g:vaffle_auto_cd = 1
" }}}
endif
" Disable unused plugins
let g:loaded_matchit = 1
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1
" Disable unused kaoriya plugins
let g:plugin_dicwin_disable = 1
" }}}
" Local settings {{{
if filereadable(s:env.path.local_vimrc)
execute 'source ' . s:env.path.local_vimrc
endif
" }}}
" Color scheme {{{
if s:plugins_activated
if !has('gui_running')
syntax enable
execute printf('colorscheme %s', s:colorscheme)
else
augroup vimrc_colorscheme
autocmd!
execute printf('autocmd GUIEnter * colorscheme %s', s:colorscheme)
augroup END
endif
if $COLORTERM ==# 'truecolor' || $COLORTERM ==# '24bit'
set termguicolors
endif
endif
" }}}