-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_vimrc.tmpl
240 lines (204 loc) · 7.31 KB
/
dot_vimrc.tmpl
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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC EDITING CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoread
set backspace=indent,eol,start
set hidden
set history=1000
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" USER INTERFACE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set background=light
set cmdheight=2
set cursorline
set laststatus=2
set mouse=a
set noshowmode
set number
set ruler
set scrolloff=3
set shortmess+=c
set showcmd
set showmatch
set sidescrolloff=5
set termguicolors
set updatetime=250
set wildmenu
{{- if eq (env "TERM") "xterm-kitty" }}
" kitty terminal workarounds
" https://sw.kovidgoyal.net/kitty/faq/#using-a-color-theme-with-a-background-color-does-not-work-well-in-vim
let &t_ut=''
" https://github.com/vim/vim/issues/11729
let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
{{- end }}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" INDENTATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoindent
set expandtab
set shiftwidth=2
let &softtabstop=&shiftwidth
filetype plugin indent on
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SEARCH
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hlsearch
set ignorecase
set incsearch
set smartcase
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TEXT
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set linebreak
set listchars=extends:▸,nbsp:⎵,precedes:◂,tab:⇥·
" Highlight trailing whitespace
match ErrorMsg /\s\+$/
syntax on
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISCELLANEOUS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set confirm
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
set viminfofile=NONE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MAPPINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Move between buffers
nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> ]B :blast<CR>
" Move between active windows
nnoremap <silent> <C-H> <C-W>h
nnoremap <silent> <C-J> <C-W>j
nnoremap <silent> <C-K> <C-W>k
nnoremap <silent> <C-L> <C-W>l
" Resize current split by +/- 5
nnoremap <silent> <C-Left> :vertical resize -5<CR>
nnoremap <silent> <C-Down> :resize +5<CR>
nnoremap <silent> <C-Up> :resize -5<CR>
nnoremap <silent> <C-Right> :vertical resize +5<CR>
" Move cursor vertically by visual line
nnoremap <silent> j gj
nnoremap <silent> k gk
" Move visual selection
xnoremap <silent> J :m '>+1<CR>gv=gv
xnoremap <silent> K :m '<-2<CR>gv=gv
" Make . work with visually selected lines
xnoremap <silent> . :normal.<CR>
" Toggle options
nnoremap yob :let &background=(&background == "dark" ? "light" : "dark")<CR>
nnoremap yoi :set ignorecase!<CR>
nnoremap yon :set number!<CR>
nnoremap yow :set wrap!<CR>
" Copy to clipboard register
vnoremap <C-C> "*y
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LEADER MAPPINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader="\<Space>"
" Clear current search highlights
nnoremap <leader><Space> :nohlsearch<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin()
Plug 'vim-airline/vim-airline'
Plug 'lifepillar/vim-gruvbox8'
Plug 'NLKNguyen/papercolor-theme'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'}
Plug 'ryanoasis/vim-devicons'
Plug 'tpope/vim-commentary'
Plug 'airblade/vim-gitgutter'
Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'sbdchd/neoformat'
call plug#end()
" airline
if !exists('g:airline_symbols')
let g:airline_symbols={}
endif
let g:airline_symbols.colnr=' '
" gruvbox8
let g:gruvbox_filetype_hi_groups=1
function! ToggleColors()
if &diff | colorscheme PaperColor | else | colorscheme gruvbox8_hard | endif
endfunction
call ToggleColors()
augroup VimDiff
autocmd!
autocmd OptionSet diff ++nested call ToggleColors()
augroup END
" fzf.vim - passing args to ripgrep
command! -bang -nargs=* RG call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".<q-args>, 1, <bang>0)
" fzf.vim - buffer delete
function! s:list_buffers()
redir => list
silent ls
redir END
return split(list, "\n")
endfunction
function! s:delete_buffers(lines)
execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
endfunction
command! BD call fzf#run(fzf#wrap({
\ 'source': s:list_buffers(),
\ 'sink*': {lines -> s:delete_buffers(lines)},
\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept'
\ }))
" NERDTree
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
" vim-gitgutter
let g:gitgutter_highlight_linenrs=1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS MAPPINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <silent> <leader>b :Buffers<CR>
nnoremap <silent> <leader>f :Files<CR>
nnoremap <silent> <leader>m :Marks<CR>
nnoremap <silent> <leader>o :<C-U>CocList outline<CR>
nnoremap <silent> <leader>t :NERDTreeToggle<CR>
nnoremap <silent> <leader>nf :NERDTreeFind<CR>
nmap <silent> <leader>rn <Plug>(coc-rename)
nmap <silent> <leader>rf <Plug>(coc-refactor)
xmap <silent> <leader>f :Neoformat<CR>
xmap <silent> <leader>a <Plug>(coc-codeaction-selected)
" Example: action in current paragraph `<leader>aap`
nmap <silent> <leader>a <Plug>(coc-codeaction-selected)
" Action in current buffer
nmap <silent> <leader>ac <Plug>(coc-codeaction)
" Fix current line
nmap <silent> <leader>qf <Plug>(coc-fix-current)
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
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)
" Map function text objects
xmap <silent> if <Plug>(coc-funcobj-i)
omap <silent> if <Plug>(coc-funcobj-i)
xmap <silent> af <Plug>(coc-funcobj-a)
omap <silent> af <Plug>(coc-funcobj-a)
" Trigger completion and navigate to next and previous items
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-H>"
" Auto-select first completion and format on enter
inoremap <silent><expr> <CR>
\ coc#pum#visible() ? coc#_select_confirm() :
\ "\<C-G>u\<CR>\<C-R>=coc#on_enter()\<CR>"
" Highlight symbol and its references when holding cursor
autocmd CursorHold * silent call CocActionAsync('highlight')
" Command to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)