-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
300 lines (233 loc) · 6.68 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
"""""""""""
" Plugins "
"""""""""""
" Install vim-plug.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Plugins managed by vim-plug.
" Specify a directory for plugins.
call plug#begin('~/.vim/plugged')
" Status line.
Plug 'itchyny/lightline.vim'
" Themes.
Plug 'NLKNguyen/papercolor-theme'
Plug 'joshdick/onedark.vim'
" Show VCS diff.
if has('nvim') || has('patch-8.0.902')
Plug 'mhinz/vim-signify'
else
Plug 'mhinz/vim-signify', { 'branch': 'legacy' }
endif
" FZF.
if has("gui_macvim")
" Mac only (assuming only MacVim is used on Mac).
Plug '/usr/local/opt/fzf'
else
Plug '/usr/bin/fzf'
endif
Plug 'junegunn/fzf.vim'
" File explorer.
" On-demand loading.
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Better syntax highlighting.
Plug 'sheerun/vim-polyglot'
" Support to edit fish scripts.
Plug 'dag/vim-fish'
" Some useful bracket key mapping.
" Like [n and ]n to move between git conflict marker.
Plug 'tpope/vim-unimpaired'
" Initialize plugin system.
call plug#end()
"""""""""""""""""""
" Plugin Settings "
"""""""""""""""""""
" Lightline.
if !has('gui_running')
set t_Co=256
endif
let g:lightline = {
\ 'colorscheme': 'one',
\ 'component': {
\ 'lineinfo': ' %3l:%-2v',
\ },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'cocstatus', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'readonly': 'LightlineReadonly',
\ 'fugitive': 'LightlineFugitive',
\ 'cocstatus': 'coc#status'
\ },
\ }
" Custom separator.
" 'separator': { 'left': '', 'right': '' },
" 'subseparator': { 'left': '', 'right': '' }
function! LightlineReadonly()
return &readonly ? '' : ''
endfunction
function! LightlineFugitive()
if exists('*fugitive#head')
let branch = fugitive#head()
return branch !=# '' ? ''.branch : ''
endif
return ''
endfunction
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" Have to specify for fish vim (even though it's set on config.fish).
let $FZF_DEFAULT_COMMAND = "find ."
" signify
" default updatetime 4000ms is not good for async update
set updatetime=100
" Open a NERDTree automatically when vim starts up if no files were specified
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" vim-polyglot
" Disable conceal (changing ',' into vertical lines)
" https://github.com/chrisbra/csv.vim#concealing
let g:csv_no_conceal = 1
""""""""""""""""""
" Plugin Rebinds "
""""""""""""""""""
" FZF
" Map fzf to ctrl-p (! to start in fullscreen.
nnoremap <silent> <C-p> :FZF!<CR>
" NERDTree
map <C-n> :NERDTreeToggle<CR>
""""""""""""
" Settings "
""""""""""""
" Copied from
" https://stackoverflow.com/questions/234564/tab-key-4-spaces-and-auto-indent-after-curly-braces-in-vim
" Turns on filetype detection, plugin, indent on.
filetype plugin indent on
" Show existing tab with 4 spaces width.
set tabstop=4
" When indenting with '>', use 4 spaces width.
set shiftwidth=4
" On pressing tab, insert 4 spaces.
set expandtab
" 2 indentation on HTML.
"autocmd FileType html setlocal shiftwidth=2 tabstop=2
syntax on
" Shows row and col numbers.
set ruler
" Shows vertical line.
set colorcolumn=100
" Shows relative line numbers.
set number
set relativenumber
" Word wrap.
set linebreak
" Highlight current line.
set cursorline
" Search as characters are entered.
set incsearch
" Highlight matches.
set hlsearch
" Show the command typed so far in bottom right corner.
set showcmd
" No automatic newline at end of file.
set nofixendofline
" Statusline appears all the time.
set laststatus=2
" No need to show '--INSERT--' on the last line
" because it is displayed in the statusline.
set noshowmode
" Cursor settings:
" 1 -> blinking block
" 2 -> solid block
" 3 -> blinking underscore
" 4 -> solid underscore
" 5 -> blinking vertical bar
" 6 -> solid vertical bar
"Mode Settings
let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
let &t_EI.="\e[2 q" "EI = NORMAL mode (ELSE)
" No delay.
set ttimeoutlen=0
" Mouse support
set mouse=a
" Open new split below or to the right of the current pane.
set splitbelow splitright
" True colors
" https://github.com/tmux/tmux/issues/1246#issue-292083184
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Colorscheme
set background=dark
colorscheme onedark
" Removes pipe | separator from vertical splits.
" Note the space at the end.
set fillchars+=vert:\
if has ('macunix')
" Mac
" Use system clipboard.
set clipboard=unnamed
if has("gui_running")
" GUI MacVim only.
set transparency=5
set macligatures
" Remove scrollbar. See :help guioptions
set guioptions-=r
endif
else
" Linux.
set clipboard=unnamedplus
" Source if exists.
" https://stackoverflow.com/a/3098685
if filereadable("/usr/share/doc/fzf/examples/fzf.vim")
source /usr/share/doc/fzf/examples/fzf.vim
endif
endif
set guifont=Fira\ Code:h14
" Fix vim background color issue.
" https://sw.kovidgoyal.net/kitty/faq.html#using-a-color-theme-with-a-background-color-does-not-work-well-in-vim
if &term == 'xterm-kitty'
let &t_ut=''
endif
"if &diff
" " Ignore whitespace in vimdiff
" set diffopt+=iwhite
"endif
"""""""""""
" Rebinds "
"""""""""""
" Remap splits navigation to just ctrl + hjkl
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Use ESC to exit insert mode in :term
tnoremap <Esc> <C-\><C-n>
" https://vim.fandom.com/wiki/Easier_buffer_switching
" Mappings to access buffers (don't use "\p" because a
" delay before pressing "p" would accidentally paste).
" \l : list buffers
" \b \f \g : go back/forward/last-used
" \1 \2 \3 : go to buffer 1/2/3 etc
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
nnoremap <Leader>f :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" https://stackoverflow.com/a/19877212
" Make double-<Esc> clear search highlights
nnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>