-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
339 lines (265 loc) · 9.16 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
"===============================================================================
" Pre-install
"===============================================================================
if !isdirectory($HOME . "/.vim-swp")
call mkdir($HOME . "/.vim-swp/undo", "p", 0700)
call mkdir($HOME . "/.vim-swp/swap", "p", 0700)
endif
"===============================================================================
" Plugins
"===============================================================================
call plug#begin()
" Intellisense engine for vim8 & neovim, full language server protocol support as VSCode
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" A light and configurable statusline/tabline plugin for Vim
Plug 'itchyny/lightline.vim'
" Things you can do with fzf and Vim.
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Theme
Plug 'morhetz/gruvbox'
" Git wrapper
Plug 'tpope/vim-fugitive'
" Quoting/parenthesizing made simple
Plug 'tpope/vim-surround'
" Comment stuff out
Plug 'tpope/vim-commentary'
"
" Vim sugar for the UNIX shell commands that need it the most.
Plug 'tpope/vim-eunuch'
"
" Combine with netrw to create a delicious salad dressing
Plug 'tpope/vim-vinegar'
" Git diff in the gutterv
Plug 'airblade/vim-gitgutter'
" Vim motions on speed!
Plug 'easymotion/vim-easymotion'
" Syntax highlighting for javascript
Plug 'pangloss/vim-javascript'
" Syntax highlighting for vue files
Plug 'posva/vim-vue'
" Seamless navigation between tmux panes and vim splits
Plug 'christoomey/vim-tmux-navigator'
" Vim plugin, insert or delete brackets, parens, quotes in pair
Plug 'jiangmiao/auto-pairs'
" Pairs of handy bracket mappings
Plug 'tpope/vim-unimpaired'
" A Vim plugin that manages your tag files
Plug 'ludovicchabant/vim-gutentags'
" Adjusts 'shiftwidth' and 'expandtab' heuristically based on the current file
Plug 'tpope/vim-sleuth'
call plug#end()
"===============================================================================
" Editor configuraton
"===============================================================================
set encoding=utf-8
" Eliminate escape delay time
set timeoutlen=1000 ttimeoutlen=0
" Theme
let g:gruvbox_contrast_light='hard'
set background=light
colorscheme gruvbox
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Enable syntax highlighting
syntax on
" Make Vim more useful
set nocompatible
" Undo and swap files
set nobackup
set undodir=~/.vim-swp/undo
set undolevels=1000 undoreload=10000
set undofile
set directory=~/.vim-swp/swap/
" Displaying status line always
set laststatus=2
" Enable line numbers
set number
" Enhance command-line completion
set wildmenu
set wildmode=list:longest,full
set wildignore=*.pyc,*.pyo,*.o
" Show “invisible” characters
set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
set list
" To insert space characters whenever the tab key is pressed
set expandtab
" Number of space characters that will be inserted when the tab key is pressed
set tabstop=4
set softtabstop=4
" How many columns text is indented with the reindent operations (<< and >>)
set shiftwidth=4
" Enable smart and auto indents
set smarttab
set autoindent
set smartindent
" Highlight searches
set hlsearch
" Ignore case of searches
set ignorecase
" Highlight dynamically as pattern is typed
set incsearch
" Always show status line
set laststatus=2
" Don’t reset cursor to start of line when moving around.
set nostartofline
" Show the current mode
set noshowmode
" Show the filename in the window titlebar
set title
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" if hidden is not set, TextEdit might fail.
set hidden
" always show signcolumns
set signcolumn=yes
"===============================================================================
" Lightline configuration
"===============================================================================
let g:lightline = {
\ 'colorscheme': 'solarized',
\ 'component_function': {
\ 'filename': 'LightlineFilename',
\ }
\ }
function! LightlineFilename()
let root = fnamemodify(get(b:, 'git_dir'), ':h')
let path = expand('%:p')
if path[:len(root)-1] ==# root
return path[len(root)+1:]
endif
return expand('%')
endfunction
"===============================================================================
" Syntax highlighing and autocomplete
"===============================================================================
let g:coc_global_extensions = [
\ 'coc-json',
\ 'coc-tsserver',
\ 'coc-html',
\ 'coc-css',
\ 'coc-vetur',
\ 'coc-yaml',
\ 'coc-python',
\ 'coc-emmet',
\ 'coc-snippets',
\ 'coc-tailwindcss',
\ 'coc-eslint',
\ 'coc-prettier',
\ ]
autocmd FileType sass setl iskeyword+=@-@
autocmd FileType scss setl iskeyword+=@-@
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
let $FZF_DEFAULT_COMMAND = 'fd --type f --hidden --follow --exclude .git'
let $FZF_DEFAULT_OPTS="--preview-window='right:50%' --layout=reverse"
let g:fzf_layout = { 'window': { 'width': 1.0, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } }
" Ctags
let g:gutentags_exclude_filetypes = [
\ 'node_modules',
\ ]
"===============================================================================
" Key bindings
"===============================================================================
" Enter empty line without entering edit mode
nmap <S-Enter> O<Esc>
nmap <CR> o<Esc>
" Refresh syntax highlighting
noremap <F12> <Esc>:syntax sync fromstart<CR>
inoremap <F12> <C-o>:syntax sync fromstart<CR>
" FZF remapping
nnoremap <C-p> :Files<Cr>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>h :History<CR>
" Strip trailing whitespace (\ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <leader>ss :call StripWhitespace()<CR>
" Copying to clipboard
noremap <Leader>y :w !pbcopy<CR><CR>
noremap <Leader>p :r !pbpaste<CR><CR>
" Tags
nnoremap <Leader>t :BTags<CR>
nnoremap <Leader>T :Tags<CR>
" Set 2 spaces for yaml
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab