-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
539 lines (463 loc) · 14.9 KB
/
.vimrc
File metadata and controls
539 lines (463 loc) · 14.9 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
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
" Author: takegue
" URL: https://github.com/takegue/dotfiles
scriptencoding utf-8
" Startup {{{ =======================
" NOTE: Skip initialization for tiny or small.
if !1 | finish | endif
if !&compatible | set nocompatible | endif " Disable vi compatible
" Echo startup time on start:{{{
if has('vim_starting') && has('reltime')
" Shell: vim --startuptime filename -q; vim filename
" vim --cmd 'profile start profile.txt' --cmd 'profile file $HOME/.vimrc' +q && vim profile.txt
let g:startuptime = reltime()
augroup VimStart
autocmd!
autocmd VimEnter *
\ let g:startuptime2 = reltime(g:startuptime)
\ | echomsg 'time:' . reltimestr(g:startuptime2)
\ | autocmd! VimStart VimEnter
augroup END
endif
" }}}
" ====================== }}}
if v:version < 740 && !has('nvim')
source ~/.min.vimrc
finish
endif
" Vim Setup ===================== {{{
"System Settings: {{{
if has('nvim')
let b:venv = tkngue#util#system("python3 -c 'import sys; print(\"vim_dev{v.major}\".format(v=sys.version_info), end=\"\")'")
let g:python3_host_prog = $HOME . '/.venv/' . b:venv . '/bin/python'
if !executable(g:python3_host_prog)
let g:python3_host_prog = substitute(tkngue#util#system('which python3'), '\v(\n|\s)+$', '', 'g')
endif
let g:python_host_prog = g:python3_host_prog
elseif has('gui_macvim')
endif
"}}}
" Display: {{{
if exists('&ambiwidth')
" For Ubuntu: gnome-terminal, terminator, guake
" /bin/sh -c "VTE_CJK_WIDTH=1 terminator -m"
" /bin/sh -c "VTE_CJK_WIDTH=1 gnome-terminal --disable-factory"
" /bin/sh -c "VTE_CJK_WIDTH=1 guake"
" https://gist.github.com/sgk/5991138
set ambiwidth=single
endif
set helplang=ja,en
set spelllang+=cjk
set title " 編集中のファイル名を表示
set ambiwidth=double " 全角文字で幅が崩れないように調整する
set laststatus=2
set number nornu
set noshowmode
set nowrap
set colorcolumn=80
set noequalalways
set winheight=8
set cindent
set shiftwidth=4
set softtabstop=4
set wildmenu wildmode=longest,full
set foldmethod=marker
set foldlevel=1
set display=lastline
set cmdheight=2
set pumheight=15
set formatoptions+=tcqM1ro
set formatoptions+=j
set nofixeol
" デフォルト不可視文字は美しくないのでUnicodeで綺麗に
set list lcs=tab:»-,trail:-,extends:»,precedes:«,nbsp:%,eol:~
set fillchars=vert:\|
" set belloff=cursor,error,insertmode
set t_vb=
" }}}
" Search: {{{
set smartcase
set wrapscan
set incsearch
set hlsearch
" Cscope: {{{
if has("cscope")
if tkngue#util#executable("gtags-cscope")
set cscopeprg=gtags-cscope
endif
set csto=0
set cst
set nocsverb
" add any database in current directory
if tkngue#util#executable("gtags-cscope")
if filereadable("GTAGS")
cs add GTAGS
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
endif
set csverb
nnoremap <Leader>n :cscope find c <C-R><C-W><CR>
endif
"}}}
" }}}
" Editing: {{{
set shiftround
set infercase
set virtualedit=all
set hidden
set switchbuf=usetab
set showmatch
set matchtime=1
set nrformats=bin,hex
set history=10000
set autoread
set updatetime=4000
" 対応括弧に'<'と'>'のペアを追加
set matchpairs+=<:>,「:」,“:”,『:』,【:】
set backspace=indent,eol,start
if !has('nvim')
set ttimeout
set ttimeoutlen=2000
endif
if has('nvim')
set clipboard=unnamed
if has('mac')
" NOTE: Performance issue and only for MacOS Settings
let g:clipboard = {
\ 'name': 'pbcopy',
\ 'copy': { '+': 'pbcopy', '*': 'pbcopy'},
\ 'paste': { '+': 'pbpaste', '*': 'pbpaste'}
\ }
elseif has('windows') && tkngue#util#executable('win32yank.exe')
" See https://github.com/equalsraf/win32yank
let g:clipboard = {
\ 'name': 'win32yank',
\ 'copy': {
\ '+': 'win32yank.exe -i',
\ '*': 'win32yank.exe -i',
\ },
\ 'paste': {
\ '+': 'win32yank.exe -o --lf',
\ '*': 'win32yank.exe -o --lf',
\ },
\ 'cache_enabled': 1,
\ }
endif
else
if has('unnamedplus')
set clipboard=unnamedplus,exclude:cons\|linux
else
set clipboard=unnamed
endif
endif
if has("persistent_undo")
set undodir=$HOME/.vim/.undodir
set undofile
set undolevels=1000
if !isdirectory("$HOME/.vim/.undodir")
call tkngue#util#mkdir(expand("$HOME/.vim/.swap"), 1)
endif
endif
set noswapfile
" set directory=$HOME/.vim/.swap
" if !isdirectory("$HOME/.vim/.swap")
" call tkngue#util#mkdir(expand("$HOME/.vim/.swap"), 1)
" endif
set writebackup
set backupdir=$HOME/.vim/.backup
set backupext=.old
if !isdirectory("$HOME/.vim/.backup")
call tkngue#util#mkdir(expand("$HOME/.vim/.backup"), 1)
endif
set backup
"}}}
" Mappings: {{{
let mapleader=","
let maplocalleader='\'
nnoremap Q <nop>
nnoremap G Gzv
"For Breaking off undo sequence.
inoremap <CR> <C-g>u<CR>
inoremap <C-h> <C-g>u<C-h>
inoremap <BS> <C-g>u<BS>
inoremap <Del> <C-g>u<Del>
inoremap <C-D> <C-g>u<Del>
inoremap <C-W> <C-g>u<C-w>
inoremap <C-U> <C-g>u<C-U>
nnoremap Y y$
vnoremap v $h
nnoremap <silent> <Space>o :call tkngue#util#open_folder_of_currentfile()<CR>
"バックスラッシュやクエスチョンを状況に合わせ自動的にエスケープ
cnoremap <expr> / getcmdtype() =~ '/' ? '\/' : '/'
cnoremap <expr> ? getcmdtype() == '?' ? '\?' : '?'
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
cnoremap <C-a> <Home>
if has('nvim')
tnoremap <Esc><Esc> <C-\><C-n>
endif
" Toggle: {{{
nnoremap [toggle] <Nop>
nmap <Leader>c [toggle]
nnoremap <silent> [toggle]s :<C-u> setl spell!<CR> : setl spell?<CR>
nnoremap <silent> [toggle]l :<C-u> setl list!<CR> : setl list?<CR>
nnoremap <silent> [toggle]t :<C-u> setl expandtab!<CR> : setl expandtab?<CR>
nnoremap <silent> [toggle]w :<C-u> setl wrap!<CR> : setl wrap?<CR>
nnoremap <silent> [toggle]z :<C-u> setl lazyredraw!<CR> : setl lazyredraw?<CR>
nnoremap <silent> [toggle]cc : setl cursorline!<CR> : setl cursorline?<CR>
nnoremap <silent> [toggle]cr : setl cursorcolumn!<CR> : setl cursorcolumn?<CR>
nnoremap <silent> [toggle]n :<C-u> call tkngue#util#toggle_line_numbers()<CR>
nnoremap <silent> [toggle]p :<C-u> set paste!<CR>
nnoremap <silent> [toggle]b :<C-u> set binary!<CR> :
nnoremap <silent> [toggle]m :<C-u>let &mouse = (&mouse == 'a' ? '' : 'a')<CR>:set mouse?<CR>
nnoremap <silent> [toggle]v :<c-u>
\:if &completeopt =~ 'preview'<CR>
\: set completeopt-=preview <CR> :pclose<CR>
\:else<CR>
\: set completeopt+=preview <CR>
\:endif<CR> :setl completeopt?<CR>
nnoremap <silent> [toggle]e :if(&colorcolumn > 0)<CR>
\: setl colorcolumn=0<CR>
\: else<CR> : setl colorcolumn=80<CR> : endif<CR>
" }}}
"
" Tab: {{{
" The prefix key.
nnoremap [Tab] <Nop>
nmap <Leader>t [Tab]
" tc 新しいタブを一番右に作る
nnoremap <silent> [Tab]c :tabnew<CR>
nnoremap <silent> [Tab]x :tabclose<CR>
" }}}
" Abbreviations: {{{
"自動で括弧内に移動
inoremap {} {}<left>
inoremap () ()<left>
inoremap [] []<left>
inoremap <> <><left>
inoremap '' ''<left>
inoremap `` ``<left>
inoremap "" ""<left>
inoremap 「」 「」<left>
inoremap 【】 【】<left>
inoremap ”” “" <left>
inoremap {}<CR> {}
inoremap ()<CR> ()
inoremap []<CR> []
inoremap {}<space> {}
inoremap ()<space> ()
inoremap []<space> []
"}}}
"}}}
"Highlight: {{{
augroup my_higlight
autocmd!
autocmd ColorScheme * call s:additional_highlight()
augroup END
function! s:additional_highlight() "{{{
if !has('gui_running')
highlight normal ctermbg=none
endif
highlight MatchParen term=inverse cterm=bold ctermfg=208 ctermbg=233 gui=bold guifg=#000000 guibg=#FD971F
highlight CursorLine cterm=bold ctermfg=lightcyan ctermbg=None gui=bold
highlight IncSearch cterm=bold ctermfg=green ctermbg=None gui=bold
highlight Search cterm=bold ctermfg=green ctermbg=None gui=bold
" highlight Normal ctermbg=none
" highlight IncSearch Search cterm=bold ctermfg=green ctermbg=None gui=bold
" highlight Visual cterm=bold ctermfg=red ctermbg=None guibg=#403D3D
" echomsg 'called adiitoinal highlight'
endfunction "}}}
"}}}
" Misc: {{{
" Open junk file
command! -nargs=? -complete=filetype Memo
\ call tkngue#util#open_junk_file('<args>')
" Todoコマンド
command! Todo call tkngue#util#open_todofile()
command! -bang -nargs=* PluginTest
\ call tkngue#util#test_plugin(<bang>0, <q-args>)
command! FollowSymlink call tkngue#util#switch_to_actualfile()
command! -nargs=1 Wget call tkngue#util#load_webpage(<q-args>)
command! -nargs=1 DiffRev call tkngue#util#get_diff_files(<q-args>)
" after/ftpluginの作成 User設定のfiletype plugin
let g:ftpPath = $HOME . "/.vim/after/ftplugin/"
nnoremap <silent> <Space>, :<C-u>call <SID>openFTPluginFile()<CR>
function! s:openFTPluginFile()
let l:ftpFileName = g:ftpPath . &filetype . ".vim"
execute 'botright vsplit ' . l:ftpFileName
endfunction
function! s:cd_project_dir() abort
let [l:path, l:lang, _] = tkngue#util#detect_project()
if isdirectory(l:path)
echomsg "AutoCD: " . l:path
exec "lcd " . l:path
endif
endfunction
function! s:my_on_filetype() abort "{{{
if &l:filetype == '' && bufname('%') == ''
return
endif
if execute('filetype') =~# 'OFF'
" Lazy loading
silent! filetype plugin indent on
filetype detect
syntax enable
" redraw!
call s:additional_highlight()
endif
endfunction "}}}
augroup TerminalSetting "{{{
autocmd!
autocmd TermOpen *
\ setl nonumber
autocmd TermOpen term://* startinsert
augroup END "}}}
augroup binaryfile "{{{
autocmd!
au BufRead * if tkngue#util#is_binary() | setl binary | %!xxd
au BufRead * set ft=xxd | endif
au BufWritePre * if &bin | %!xxd -r
au BufWritePre * endif
au BufWritePost * if &bin | %!xxd
au BufWritePost * set nomod | endif
augroup END "}}}
augroup edit_vimrc "{{{
autocmd!
" autocmd BufReadPost $MYVIMRC setlocal path+=$HOME/.vim/bundle
autocmd BufRead bundles.toml execute "setlocal path+=" . substitute(glob(s:cache_home . "/repos/*"), '\n', ',', 'g')
" autocmd BufReadPost bundles.toml execute "setlocal tags+=" . substitute(glob(s:cache_home . "/repos/*"), '\n', ',', 'g')
autocmd BufReadPost $MYVIMRC execute "setlocal tags+=" . substitute(glob("$HOME/.vim/bundle/**/.git/tags"), '\n', ',', 'g')
autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
autocmd BufWritePost bundles.toml source $MYVIMRC
autocmd BufWritePost ~/.dotfiles/.vimrc nested source $MYVIMRC
augroup END "}}}
if tkngue#util#executable("ghq")
let s:ghq_path = tkngue#util#system("ghq root")
execute "set path+=" . substitute(glob(s:ghq_path . "/*"), '\n', ',', 'g')
endif
augroup MyAutocmdGroup "{{{
autocmd!
autocmd BufNewFile,BufRead *.todo
\ set nonumber norelativenumber filetype=markdown
" diff
autocmd InsertLeave *
\ if &diff | diffupdate | echo 'diff updated' | endif
" large_file_config_for_smooth
autocmd BufNewFile,BufRead * if &filetype != 'help' && line('$') > 10000 |
\ setl nonumber norelativenumber nocursorline|
\ filetype plugin indent off |
\ setl syntax=off |
\ endif
autocmd BufWritePre * call tkngue#util#mkdir(expand('<afile>:p:h'), v:cmdbang)
autocmd QuickfixCmdPost make,diff,grep,grepadd,vimgrep,vimdiff copen
autocmd CmdwinEnter * nnoremap <buffer>q <C-w>c
autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} set filetype=markdown
autocmd BufNewFile,BufRead *.ipynb set filetype=json
autocmd BufNewFile,BufRead *.gs set filetype=javascript
" autocmd BufReadPost * call s:SwitchToActualFile()
autocmd FileType sh,zsh,csh,tcsh let &l:path = substitute($PATH, ':', ',', 'g')
autocmd BufWinEnter * call tkngue#util#restore_curosr_position()
" help, quickfix settings
autocmd FileType lspinfo,help,qf nnoremap <buffer> q <C-w>c
autocmd FileType help nnoremap <buffer> <CR> <C-]>
autocmd FileType help nnoremap <buffer> <BS> <C-o>
" MEMO: Shdo するさいに lcdしてしまうのがうざいのでdisabled
" autocmd BufRead * call s:cd_project_dir()
autocmd VimEnter * if filereadable(expand("./.vimrc.local"))
\ | execute 'source ' . expand("./.vimrc.local")
\ | endif
autocmd DirChanged * if filereadable(expand("<afile>/.vimrc.local"))
\ | execute 'source ' . expand("<afile>/.vimrc.local")
\ | endif
autocmd FileType,Syntax,BufNewFile,BufNew,BufRead *
\ call s:my_on_filetype()
augroup END
"}}}
"}}}
"}}}
" Plugin Settings ============== {{{
" Standard Vim plugins {{{
let g:loaded_2html_plugin = 1
let g:loaded_logiPat = 1
let g:loaded_getscriptPlugin = 1
" let g:loaded_gzip = 1
" let g:loaded_man = 1
" let g:loaded_matchit = 1
" let g:loaded_matchparen = 1
let g:loaded_netrwFileHandlers = 0
let g:loaded_netrwPlugin = 0
" let g:loaded_netrwSettings = 1
" let g:loaded_rrhelper = 1
let g:loaded_shada_plugin = 1
" let g:loaded_spellfile_plugin = 1
let g:loaded_tarPlugin = 1
let g:loaded_tutor_mode_plugin = 1
let g:loaded_vimballPlugin = 1
" let g:loaded_zipPlugin = 1
"}}}
" dein.vim Initilization {{{
let g:noplugin = &compatible ? 1 : 0
if !g:noplugin
let s:cache_home = empty($XDG_CACHE_HOME) ? expand('~/.cache') : $XDG_CACHE_HOME
let s:cache_home = s:cache_home . '/dein'
" Load dein.
let s:dein_dir = finddir('dein.vim', '.;')
let s:dein_repo = expand(s:cache_home) . '/repos/github.com/Shougo/dein.vim'
if s:dein_dir == '' && &runtimepath !~ '/dein.vim'
if !isdirectory(s:dein_repo)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo
endif
endif
execute 'set runtimepath^=' . substitute(fnamemodify(s:dein_repo, ':p') , '/$', '', '')
if dein#load_state(s:cache_home)
call dein#begin(s:cache_home)
call dein#load_toml('~/.vim/bundles.toml')
call dein#end()
call dein#save_state()
endif
autocmd VimEnter * call dein#call_hook('post_source')
if !has('vim_starting') && dein#check_install()
" Installation check.
call dein#install()
endif
endif
" END dein}}}
"}}}
" Local settings ================ {{{
let s:local_vimrc = expand('~/.local.vimrc')
if filereadable(s:local_vimrc)
execute 'source ' . s:local_vimrc
endif
" }}}
" Finally ======================={{{
" Colorscheme: {{{
" Check color
" :so $VIMRUNTIME/syntax/colortest.vim
" Check syntax
" :so $VIMRUNTIME/syntax/hitest.vim
if has('gui_running')
colorscheme PaperColor
elseif has('vim_starting')
set background=dark
if &t_Co < 256
colorscheme default
else
try
set termguicolors
colorscheme molokai
catch
colorscheme blue
endtry
endif
set t_Co=256
syntax sync minlines=512
filetype plugin indent off
syntax off
else
call dein#call_hook('source')
call dein#call_hook('post_source')
endif
"}}}
"}}}
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker number nornu