-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·441 lines (424 loc) · 14 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
"オートコマンドを初期化
autocmd!
syntax on
filetype plugin indent on
colorscheme desert
let mapleader=","
"" -------------------
"" ハイライト
"" -------------------
"{{{1
"ステータスライン"{{{2
let &statusline = ''
let &statusline .= '%<%F %h%m%r%w'
let &statusline .= '%='
let &statusline .= '%y' " filetype
let &statusline .= '[%{&fileencoding == "" ? &encoding : &fileencoding}]'
let &statusline .= '[%{&fileformat}]'
let &statusline .= ' %-14.(%l,%c%V%) %P'
autocmd ColorScheme * highlight StatusLine cterm=bold,reverse ctermfg=blue ctermbg=white
autocmd ColorScheme * highlight StatusLineNC cterm=reverse
" ステータスラインの色(挿入モード:green,ノーマルモード:blue)
autocmd InsertEnter * highlight StatusLine ctermfg=green
autocmd InsertLeave * highlight StatusLine ctermfg=blue
"}}}
"
" ポップアップメニュー"{{{2
autocmd ColorScheme * highlight Pmenu ctermbg=lightblue
autocmd ColorScheme * highlight PmenuSel ctermbg=darkgrey
"}}}
" テキストライン"{{{2
highlight LineNr ctermfg=darkyellow " 行番号
highlight NonText ctermfg=darkgrey
highlight Folded ctermfg=blue
highlight SpecialKey cterm=underline ctermfg=darkgrey
highlight SpecialKey ctermfg=grey " 特殊記号
" 全角空白と行末の空白の色を変える
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
autocmd WinEnter * match WhitespaceEOL /\s\+$/
"行頭のスペースの連続をハイライトさせる
"Tab文字も区別されずにハイライトされるので、区別したいときはTab文字の表示を別に
"設定する必要がある。
function! SOLSpaceHilight()
syntax match SOLSpace "^\s\+" display containedin=ALL
highlight SOLSpace term=underline ctermbg=LightGray
endf
"全角スペースをハイライトさせる。
function! JISX0208SpaceHilight()
syntax match JISX0208Space " " display containedin=ALL
highlight JISX0208Space term=underline ctermbg=LightCyan
endf
"syntaxの有無をチェックし、新規バッファと新規読み込み時にハイライトさせる
if has("syntax")
syntax on
augroup invisible
autocmd! invisible
"autocmd BufNew,BufRead * call SOLSpaceHilight()
autocmd BufNew,BufRead * call JISX0208SpaceHilight()
augroup END
endif"}}}
"タブ文字と終末スペースと改行文字の文字指定
set listchars=tab:»\ ,trail:-,eol:↲
"tabの色
highlight TabLine term=reverse cterm=reverse ctermfg=white ctermbg=black
highlight TabLineSel term=bold cterm=bold,underline ctermfg=yellow
highlight TabLineFill term=reverse cterm=reverse ctermfg=white ctermbg=black
"}}}
"" -------------------
"" オプション
"" -------------------
"{{{
set foldmethod=marker
set foldcolumn=4
set complete=.,w,b,t,i,k
set whichwrap=b,s,h,l,<,>,[,]
set cinoptions=g0,j1
set dictionary=~/.vim/dict/hotchpotch.dict
set completeopt=menu,preview,menuone
set lazyredraw
set hlsearch
set backspace=eol,indent,start
set number
" 括弧入力時に対応する括弧を表示
set showmatch
" 移動キーを押しても括弧の強調を有効にする
set cpoptions-=m
set matchtime=3
" <>にもマッチするようにする
set matchpairs+=<:>
set scrolloff=1000
set laststatus=2
set tags=.tags;
set showcmd
set foldmethod=marker
set linebreak
set history=1000
set helplang=ja
set keywordprg=:help
set showtabline=2
set tabline=%!MyTabLine()
function! MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
let s .= '%' . (i+1) . 'T'
let s .= ' ' . (i+1) . (1==getwinvar(i+1,'&modified')?'[+]':'') . ' %{MyTabLabel(' . (i+1) . ')} '
endfor
let s .= '%#TabLineFill#%T'
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'
endif
return s
endfunction
function! MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
return bufname(buflist[winnr - 1])
endfunction
" 矩形選択で文字が無くても右へ進めるようにする
set virtualedit=block
" 検索文字を打ち込むと即検索する(インクリメンタルサーチ)
set incsearch
" 単語補完時に大文字小文字を上手く区別"
set infercase
" :e .v<TAB><TAB> した時に補完候補を表示
set wildmenu
set wildmode=list:longest,full
" swpファイル出力場所
set directory=~/tmp
"" タブ幅
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=4
"" タブ文字と改行文字を表示(^I,$)
set list
"" 検索時に大文字小文字区別しない
set ignorecase
set smartcase
"" バッファを切り替えてもundoの効力を保たせる
set hidden
"" 後方検索時に文字列が見つからない場合にファイルの先頭に戻って再検索する
set wrapscan
set modifiable
set fencs=utf-8,euc-jp,cp932,ucs-bom,ucs-2le,ucs-2,iso-2022-jp-3
"}}}
"" -------------------
"" キーマッピング
"" -------------------
"{{{
noremap <leader>. :<C-u>edit ~/dotfiles/.vimrc<CR>
noremap <leader>s :<C-u>source $MYVIMRC<CR>
noremap <leader>v :<C-u>edit ~/dotfiles/.vimperatorrc<CR>
" ヘルプ表示
autocmd FileType help nnoremap <buffer> q <C-w>c
nnoremap <C-h> :<C-u>help<Space>
nnoremap <C-h><C-h> :<C-u>help<Space><C-r><C-w><CR>
" タブ切り替え
nnoremap <silent> <C-n> :<C-u>tabnext<cr>
nnoremap <silent> <C-p> :<C-u>tabprevious<CR>
nnoremap <silent> tn :<C-u>tabnew<CR>
nnoremap <silent> tq :<C-u>tabclose<CR>
" 表示行単位で移動
noremap j gj
noremap k gk
vnoremap j gj
vnoremap k gk
noremap gj j
noremap gk k
vnoremap gj j
vnoremap gk k
" 同じ名前のヘッダファイルを開く
nnoremap <C-^> :<C-u>hide edit %<.hpp<Return>
"挿入モードで貼り付け
inoremap <C-v> <ESC>"*pa
" 選択部分をクリップボードにコピー
vnoremap <C-C> "*y
" 選択部分をクリップボードの値に置き換え
vnoremap <C-V> d"*P
" コマンドライン時、クリップボードから貼り付け
cnoremap <C-V> <C-R>*
" 選択部分をクリップボードに切り取り
vnoremap <C-X> "*d<ESC>
"挿入モードでのEsc割り当て
inoremap jj <Esc>j
inoremap ;; <Esc>
inoremap kk <Esc>k
inoremap hh <Esc>^
"アンドゥ位置設定 :help i_ctrl-G_u
inoremap <C-u> <C-g>u<C-u>
inoremap <C-w> <C-g>u<C-w>
inoremap <C-h> <C-g>u<C-h>
"はてな記法的な何か
inoremap <leader>* <h4></h4><Esc>4hi
inoremap <leader>** <h5></h5><Esc>4hi
"ESC連打で強調表示切る
nnoremap <Esc><Esc> :<C-u>nohlsearch<CR>
nnoremap <C-l> W
nnoremap <leader>w :<C-u>write<CR>
"カーソル移動
cnoremap <C-h> <Backspace>
cnoremap <C-l> <Right>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-b> <Left>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-d> <Del>
inoremap <C-h> <Backspace>
inoremap <C-l> <Right>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-b> <C-o>b
inoremap <C-a> <Home>
inoremap <C-f> <Esc>f
inoremap <C-f><C-f> <Esc>F
inoremap :w <Esc>:write<CR>
inoremap <leader>w <Esc>:write<CR>
inoremap <C-e> <End>
inoremap <C-d> <Del>
inoremap <leader>[ [
inoremap <leader>{ {
inoremap <leader>( (
inoremap <leader>; <End>;
nnoremap <leader>; A;
"コマンドモードの履歴
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
"日付入力
inoremap <expr> <leader>df strftime('%Y-%m-%dT%H:%M:%S')
inoremap <expr> <leader>dd strftime('%Y-%m-%d')
inoremap <expr> <leader>dt strftime('%H:%M:%S')
"最後に変更が行われたテキストを選択
nnoremap gc `[v`]
vnoremap gc :<C-u>normal gc<CR>
onoremap gc :<C-u>normal gc<CR>
" バッファのディレクトリをカレントディレクトリにする
command! -nargs=? -complete=dir -bang CD call s:ChangeCurrentDir('<args>', '<bang>')
function! s:ChangeCurrentDir(directory, bang)
if a:directory == ''
lcd %:p:h
else
execute 'lcd' . a:directory
endif
if a:bang == ''
pwd
endif
endfunction
" Change current directory.
nnoremap <silent> <leader>cd :<C-u>CD<CR>
"vimの戦闘力
nnoremap ,vim :call <SID>GetVimPower()<CR>
function! s:GetVimPower()
echo len(filter(readfile($MYVIMRC),'v:val !~ "^\\s*$\\|^\\s*\""'))
endfunction
"}}}
" Gtags
"map <C-i> :Gtags -f %<CR>
noremap <C-g> :GtagsCursor<CR>
noremap g<C-n> :cn<CR>
noremap g<C-p> :cp<CR>
let g:Align_xstrlen = 3
set viminfo+=!
map <silent> <C-T> :call BufferList()<CR>
" C/Migemo
if has('migemo')
set migemo
set migemodict=$VIM/dict/utf-8.d/migemo-dict
endif
" surround.vim
nmap s <Plug>Ysurround
nmap ss <Plug>Yssurround
nmap <leader>q <Plug>Csurround w"
imap <leader>q <Esc><Plug>Csurround w"<Right>wa
nmap <leader>sq <Plug>Csurround w'
imap <leader>sq <Esc><Plug>Csurround w'<Right>wa
" gfは新しいタブで
map gf <C-w>gf
" タブでたくさん開く
set tabpagemax=1000
command! Rearrange :only|:tabonly|:tab sball
""-------------------------------------------------------------------
" Screenのステータスラインに編集中のファイルを表示し、
" 終了時にはShellと表示する。※^[ はctrl + v を押しながら [
"-------------------------------------------------------------------
"{{{
function! SetScreenTabName(name)
let arg = 'k' . a:name . ' > vim \\'
silent! exe '!echo -n "' . arg . "\""
endfunction
"Screenの場合にvimを使用した時にスクリーンタブ名を書き換える
if &term =~ "screen"
autocmd VimLeave * call SetScreenTabName('shell')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | call SetScreenTabName("%") | endif
endif
"}}}
""-------------------------------------------------------------------
" コンソールラインを必要な時だけ表示する
" http://d.hatena.ne.jp/thinca/20090530/1243615055
""-------------------------------------------------------------------
"{{{
set cursorline
highlight CursorLine cterm=inverse
augroup vimrc-auto-cursorline
autocmd!
autocmd CursorMoved,CursorMovedI * call s:auto_cursorline('CursorMoved')
autocmd CursorHold,CursorHoldI * call s:auto_cursorline('CursorHold')
autocmd WinEnter * call s:auto_cursorline('WinEnter')
autocmd WinLeave * call s:auto_cursorline('WinLeave')
let s:cursorline_lock = 0
function! s:auto_cursorline(event)
if a:event ==# 'WinEnter'
setlocal cursorline
let s:cursorline_lock = 2
elseif a:event ==# 'WinLeave'
setlocal nocursorline
elseif a:event ==# 'CursorMoved'
if s:cursorline_lock
if 1 < s:cursorline_lock
let s:cursorline_lock = 1
else
setlocal nocursorline
let s:cursorline_lock = 0
endif
endif
elseif a:event ==# 'CursorHold'
setlocal cursorline
let s:cursorline_lock = 1
endif
endfunction
augroup END
"}}}
"自動的に QuickFix リストを表示する
autocmd QuickfixCmdPost make,grep,grepadd,vimgrep,vimgrepadd cwin
autocmd QuickfixCmdPost lmake,lgrep,lgrepadd,lvimgrep,lvimgrepadd lwin
"{{{
function! SetScreenTabName(name)
let arg = 'k' . a:name . ' > vim \\'
silent! exe '!echo -n "' . arg . "\""
endfunction
"Screenの場合にvimを使用した時にスクリーンタブ名を書き換える
if &term =~ "screen"
autocmd VimLeave * call SetScreenTabName('shell')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | call SetScreenTabName("%") | endif
endif
"}}}
"バッファで開かれてるファイルのフルパス
"http://d.hatena.ne.jp/ns9tks/20090904/1252073153
command! YankPath let @* = expand('%:p')
if has("autocmd")
autocmd FileType python let g:pydiction_location = '~/.vim/pydiction/complete-dict'
autocmd FileType python setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
endif " has("autocmd")
" Execute python script ,t
function! s:ExecPy()
exe "!" . &ft . " %"
endfunction
command! Exec call <SID>ExecPy()
autocmd FileType python nnoremap <leader>t :call <SID>ExecPy()<CR>
"--------------
let g:neocomplcache_enable_at_startup = 1
let g:neocomplcache_disable_auto_select_buffer_name_pattern = '.*'
let g:neocomplcache_enable_ignore_case = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_auto_completion_start_length = 3
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_enable_auto_delimiter = 1
if &filetype == 'scala'
setlocal iskeyword+=@-@
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
setlocal suffixesadd=.scala
setlocal suffixes+=.class
setlocal comments& comments^=sO:*\ -,mO:*\ \ ,exO:*/
setlocal commentstring=//%s
setlocal formatoptions-=t formatoptions+=croql
setlocal dict=$HOME/.vim/dict/java.dict,$HOME/.vim/dict/scala.dict
endif
""" unite.vim
" 入力モードで開始する
let g:unite_enable_start_insert=1
let g:unite_enable_split_vertically = 1 "縦分割で開く
let g:unite_winwidth = 40 "横幅40で開く
" バッファ一覧
nnoremap <silent> ,ub :<C-u>Unite buffer<CR>
" ファイル一覧
nnoremap <silent> ,uf :<C-u>UniteWithBufferDir -buffer-name=files file<CR>
" レジスタ一覧
nnoremap <silent> ,ur :<C-u>Unite -buffer-name=register register<CR>
" 最近使用したファイル一覧
nnoremap <silent> ,um :<C-u>Unite file_mru<CR>
" 常用セット
nnoremap <silent> ,uu :<C-u>Unite buffer file_mru<CR>
" 全部乗せ
nnoremap <silent> ,ua :<C-u>UniteWithBufferDir -buffer-name=files buffer file_mru bookmark file<CR>
" アウトライン
nnoremap <silent> ,uo :<C-u>Unite outline<CR>
" ウィンドウを縦に分割して開く
au FileType unite nnoremap <silent> <buffer> <expr> <C-l> unite#do_action('vsplit')
au FileType unite inoremap <silent> <buffer> <expr> <C-l> unite#do_action('vsplit')
" ESCキーを2回押すと終了する
au FileType unite nnoremap <silent> <buffer> <ESC><ESC> q
au FileType unite inoremap <silent> <buffer> <ESC><ESC> <ESC>q
" Use Hatena.vim
let g:hatena_user='voidy21'
" Use git-vim
"{{{
let g:git_no_map_default = 1
let g:git_command_edit = 'rightbelow vnew'
nnoremap <Leader>gd :<C-u>GitDiff --cached<CR>
nnoremap <Leader>gD :<C-u>GitDiff<CR>
nnoremap <Leader>gs :<C-u>GitStatus<CR>
nnoremap <Leader>gl :<C-u>GitLog<CR>
nnoremap <Leader>ga :<C-u>GitAdd<CR>
nnoremap <Leader>gA :<C-u>GitAdd <cfile><CR>
nnoremap <Leader>gc :<C-u>GitCommit<CR>
nnoremap <Leader>gC :<C-u>GitCommit --amend<CR>
nnoremap <Leader>gp :<C-u>Git push
autocmd FileType git-* nnoremap <buffer> q <C-w>c
"}}}