-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimrc
More file actions
380 lines (310 loc) · 10.9 KB
/
Copy pathvimrc
File metadata and controls
380 lines (310 loc) · 10.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
" _/_/_/_/ Initialization _/_/_/_/
filetype off " Disable filetype temporary; re-enable it at the end
" _/_/_/_/ Common settings _/_/_/_/
syntax enable
set encoding=utf-8
set fileencodings=utf-8,sjis,euc
set fileformats=unix,dos,mac
set directory=~/.vim/swap " Directory for swap files
set backupdir=~/.vim/backup " Directory for backup files
set number " Show line numbers
set incsearch " Enable incremental search
set hlsearch " Highlight search targets
set ignorecase smartcase " Ignore case when searching only with small letters
set showmatch " Highlight matching brackets
set showmode " Show current mode of Vim
set title " Show editing file title
set ruler " Show ruler
set expandtab " Put white-spaces when type tab
set tabstop=2 " Tab width
set shiftwidth=2 " Indent width
set softtabstop=2 " Moving width of cursor to consecutive spaces when type tab, backspace, etc.
set autoindent " Follow indent width of the previous line when starting a new line
set smartindent " Indent nicely for C-like programs when starting a new line
set scrolloff=10 " Show 10 lines below cursor when scrolling
set backspace=indent,eol,start " Enable backspace key
set virtualedit=block " Remove the cursor restriction on rectangular selection
set ambiwidth=single " Make ambiguous width single (Note: Coordinate settings of Vim and terminal)
set wrap " Wrap long lines
set breakindent
set breakindentopt=shift:4
set nofoldenable " Disable text folding (Note: can be enabled by `zi`)
set foldmethod=indent " Create folds based on indent
set clipboard=unnamed,unnamedplus " Copy it to clipboard on yanking text
set spell " Enable spell check
set spelllang+=cjk " Exclude Japanese on spell check
set complete-=i " Do not scan included filesin completion
set completeopt=menuone,noinsert " Prevent automatic selection in completion
set mouse=a " Enable mouse
set laststatus=2 " Display status line always
set iskeyword+=- " Treat a hyphenated word as a single word
set vb t_vb= " Disable beep sound
set t_BE= " Prevent entering bracketed paste mode
set t_Co=256 " Use 256 color mode
" Copy yanked text to the clipboard on exit (for Linux)
autocmd VimLeave * call system("xsel -ib", getreg('+'))
" Open QuickFix on running vimgrep
autocmd QuickFixCmdPost *grep* cwindow
" Change background color on 81-100 characters of lines
execute "set colorcolumn=" . join(range(81,100), ',')
" Indent width by language
augroup languageSpecific
autocmd! FileType cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 breakindentopt=shift:8
autocmd! FileType java setlocal tabstop=4 shiftwidth=4 softtabstop=4 breakindentopt=shift:8
autocmd! FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 breakindentopt=shift:8
augroup END
" Show invisible characters
set list
set listchars=tab:»-,trail:-,eol:¬,extends:»,precedes:«,nbsp:%
" Show zenkaku whitespace
highlight ZenkakuSpace cterm=underline ctermfg=lightblue guibg=darkgray
match ZenkakuSpace / /
" Configure undo feature
if has('persistent_undo')
set undodir=~/.vim/undo
set undofile
set undolevels=1000
set undoreload=10000
endif
" Enable matchit (enable to jump to matching keyword by '%')
if !exists('loaded_matchit')
runtime macros/matchit.vim
endif
" Run keyword completion on inputting characters
for k in split("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",'\zs')
exec "inoremap " . k . " " . k . "<C-N><C-P>"
endfor
" **************************************
" * Key mappings *
" **************************************
" Cancel search highlighting by typing ESC key twice
nnoremap <silent> <Esc><Esc> :nohlsearch<LF>
" Show a list when there are multiple targets of tag jumping
nnoremap <C-]> g<c-]>
" Enable omni completion by Ctrl+F
inoremap <C-F> <C-X><C-O>
" Keep the cursor at the current word when * is pressed
" ref: https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump
nnoremap * :keepjumps normal! mi*`i<CR>
" Resize panes simply
nnoremap < <C-w><
nnoremap > <C-w>>
nnoremap + <C-w>+
nnoremap - <C-w>-
" Disable Ex mode
map Q <Nop>
" **************************************
" * Configuration for tab feature *
" **************************************
" Anywhere SID
function! s:SID_PREFIX()
return matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSID_PREFIX$')
endfunction
" Set tabline
function! s:my_tabline()
let s = ''
for i in range(1, tabpagenr('$'))
let bufnrs = tabpagebuflist(i)
let bufnr = bufnrs[tabpagewinnr(i) - 1] " first window, first appears
let no = i " display 0-origin tabpagenr.
let mod = getbufvar(bufnr, '&modified') ? '!' : ' '
let title = fnamemodify(bufname(bufnr), ':t')
let title = '[' . title . ']'
let s .= '%'.i.'T'
let s .= '%#' . (i == tabpagenr() ? 'TabLineSel' : 'TabLine') . '#'
let s .= no . ':' . title
let s .= mod
let s .= '%#TabLineFill# '
endfor
let s .= '%#TabLineFill#%T%=%#TabLine#'
return s
endfunction
let &tabline = '%!'. s:SID_PREFIX() . 'my_tabline()'
" The prefix key.
nnoremap [Tab] <Nop>
nmap t [Tab]
" Tab jump: from [Tab]1 to [Tab]2
for n in range(1, 9)
execute 'nnoremap <silent> [Tab]'.n ':<C-u>tabnext'.n.'<CR>'
endfor
set showtabline=2 " Show tab line
noremap <silent> [Tab]c :tablast <bar> tabnew<CR>
noremap <silent> [Tab]x :tabclose<CR>
noremap <silent> [Tab]n :tabnext<CR>
noremap <silent> [Tab]p :tabprevious<CR>
" Visual @
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
" _/_/_/_/ Vim Plug _/_/_/_/
call plug#begin()
" >>>> Plug-ins >>>>
" General
Plug 'joshdick/onedark.vim'
Plug 'Shougo/vimproc.vim', { 'do' : 'make' }
Plug 'junegunn/fzf', { 'merged': 0 }
Plug 'junegunn/fzf.vim', { 'depends': 'fzf' }
Plug 'tpope/vim-surround'
Plug 'thinca/vim-qfreplace'
Plug 'scrooloose/nerdtree'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'itchyny/lightline.vim'
Plug 'thinca/vim-quickrun'
Plug 'mileszs/ack.vim'
Plug 'mbbill/undotree'
Plug 'godlygeek/tabular'
Plug 'tpope/vim-fugitive'
Plug 'cohama/lexima.vim'
Plug 'w0rp/ale'
" Language specific
Plug 'dag/vim2hs'
Plug 'slim-template/vim-slim'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'mxw/vim-jsx'
Plug 'moll/vim-node'
Plug 'mustache/vim-mustache-handlebars'
Plug 'Vimjas/vim-python-pep8-indent'
Plug 'keith/swift.vim'
" <<<< Plug-ins <<<<
call plug#end()
" >>>> Settings for plug-ins >>>>
" **************************************
" * fzf.vim *
" **************************************
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit'
\}
let g:fzf_history_dir = '~/.vim/fzf-history'
let g:fzf_layout = { 'down': '~35%' }
let g:fzf_colors = {
\ 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment']
\}
" Run fzf.vim by Ctrl+P
noremap <C-p> :FZF<CR>
" Run fzf.vim when opening Vim without specifying any files
function FzfIfEmpty()
if @% == ""
" ref: https://github.com/junegunn/fzf.vim/issues/368#issuecomment-302150831
call feedkeys(":FZF!\<CR>", 'n')
endif
endfunction
augroup AutoFzf
autocmd!
autocmd VimEnter * call FzfIfEmpty()
augroup END
" **************************************
" * NERDTree *
" **************************************
let NERDTreeShowHidden = 1 " Show hidden files
" **************************************
" * vim-indent-guides *
" **************************************
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=#444433 ctermbg=235
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#333344 ctermbg=236
" **************************************
" * lightline *
" **************************************
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'relativepath', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ], [ 'percent' ], [ 'filetype' ] ],
\ },
\ 'inactive': {
\ 'left': [ [ 'relativepath' ] ],
\ },
\}
" " Copied from lightline#tab#filename(n) in lightline.vim/autoload/lightline/tab.vim
" " except that it adds a relative path from the root (the same as relativepath above)
" function! CustomTabname(n) abort
" let buflist = tabpagebuflist(a:n)
" let winnr = tabpagewinnr(a:n)
" let _ = expand('#'.buflist[winnr - 1].'%:t') " % is added here
" return _ !=# '' ? _ : '[No Name]'
" endfunction
"
" " Copied from the default except for filename
" let g:lightline.tab_component_function = {
" \ 'filename': 'CustomTabname',
" \ 'modified': 'lightline#tab#modified',
" \ 'readonly': 'lightline#tab#readonly',
" \ 'tabnum': 'lightline#tab#tabnum'
" \}
" **************************************
" * vim-quickrun *
" **************************************
let g:quickrun_config = {
\ "_" : {
\ "runner" : "vimproc",
\ "runner/vimproc/updatetime" : 60,
\ "outputter" : "error",
\ "outputter/error/success" : "buffer",
\ "outputter/error/error" : "quickfix",
\ "outputter/buffer/split" : ":botright 8sp",
\ "hook/time/enable" : 1
\ },
\ "cpp" : {
\ "type" : "cpp/g++"
\ },
\ "cpp/g++" : {
\ "cmdopt" : "-std=c++11 -Wall",
\ }
\}
" :r closes QuickFix then runs QuickVim
let g:quickrun_no_default_key_mappings = 1
nnoremap ,r :cclose<CR>:QuickRun -mode n<CR>
xnoremap ,r :<C-U>cclose<CR>gv:QuickRun -mode v<CR>
" <C-c> kills running QuickVim forcibly
nnoremap <expr><silent> <C-c> quickrun#is_running() ? quickrun#sweep_sessions() : "\<C-c>"
" **************************************
" * ack.vim *
" **************************************
let g:ackprg = 'rg --vimgrep --no-heading --hidden --glob "!.git/*"'
" <C-f> triggers ":Ack! " which doesn't open the first match
nnoremap <C-f> :Ack!
" **************************************
" * Ale *
" **************************************
let g:ale_linters = {
\ 'javascript': ['eslint', 'tsserver'],
\ 'ruby': ['rubocop'],
\}
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'ruby': ['rubocop'],
\}
" Key mappings
nnoremap R :ALEFindReferences<CR>
nnoremap H :ALEHover<CR>
nnoremap gd :ALEGoToDefinition<CR>
" **************************************
" * vim2hs *
" **************************************
let g:haskell_conceal = 0
" <<<< Settings for plug-ins <<<<
" _/_/_/_/ Enable per-project .vimrc _/_/_/_/
set exrc
set secure
" _/_/_/_/ Finalization _/_/_/_/
colorscheme onedark " Installed via the plugin
filetype plugin indent on " Re-enable filetype