-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
371 lines (318 loc) · 10.5 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
" {{{ TOC
" - Prologue
" - Plugins installation
" - General customizations
" - Plugin customization
" - Filetype/Language specific customizations
" - LSP customizations
" - Abbreviations
" - Misc helpers
" }}}
" Prologue {{{
" Enable modern Vim features not compatible with Vi spec.
set nocompatible
" Needed for now by Vundle
filetype off
" }}}
" {{{ Plugins installation
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
if isdirectory(expand('$HOME/.vim/bundle/Vundle.vim'))
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" tmux
" Allows sending keys to another tmux pane from within vim
Plugin 'benmills/vimux'
" Allows using the same keys to navigate vim panes and tmux panes.
" This overwrites Ctrl-{h,j,k,l}, which usually behaves the same as
" non-Ctrl.
Plugin 'christoomey/vim-tmux-navigator'
" fuzzy find interface for files, buffers, history, etc.
Plugin 'junegunn/fzf.vim'
" quickly jump to a specific letter visible on the screen
Plugin 'easymotion/vim-easymotion'
" LSP related functionality
" Needed for async commands to work right.
Plugin 'prabirshrestha/async.vim'
" LSP client
Plugin 'prabirshrestha/vim-lsp'
" Autocompletion
Plugin 'prabirshrestha/asyncomplete.vim'
" Use LSP as autocomplete source
Plugin 'prabirshrestha/asyncomplete-lsp.vim'
" Use buffer as autocomplete source
Plugin 'prabirshrestha/asyncomplete-buffer.vim'
" Use file names as autocomplete source
Plugin 'prabirshrestha/asyncomplete-file.vim'
" Use words in tmux panes for completion.
Bundle 'wellle/tmux-complete.vim'
if has('python3')
" Track the engine.
Plugin 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'
" UltiSnips source for asyncomplete.vim
Plugin 'prabirshrestha/asyncomplete-ultisnips.vim'
endif
" Easily comment out lines/selection with gc
Plugin 'tpope/vim-commentary'
" Helpers to deal with 'surrounding' stuff
Plugin 'tpope/vim-surround'
" Vim plugin for Git, or Git plugin for Vim.
Plugin 'tpope/vim-fugitive'
call vundle#end()
else
echomsg 'Vundle is not installed. You can install Vundle from'
\ 'https://github.com/VundleVim/Vundle.vim'
endif
" }}}
" Customizations {{{
" Enable filetype detection and turn on plugin and indent files
filetype plugin indent on
" Enable syntax (lexcial) highlighting
syntax on
set enc=utf-8
set backspace=indent,eol,start " Make backspace sane.
set scrolloff=5 " Add top/bottom scroll margins.
set history=5000 " Remeber more command line history
set wildmenu " Enhanced completion.
set wildmode=list:longest " Act like shell completion.
set splitbelow splitright " Windows are created in the direction I read.
" Make hidden characters look nice when shown.
" doesn't really work without set list
set list
set listchars=tab:▷\ ,trail:¬,extends:»,precedes:«
" set listchars=tab:▷\ ,eol:¬,extends:»,precedes:«
set colorcolumn=100
set fillchars=vert:│ " separator between windows
set noswapfile
set mouse="a" " Enable mouse, may be useful for terminal-debug.
set laststatus=2 " Always show a status line
set matchpairs+=<:> " Jump between angle brackets.
" }}}
" Mappings {{{
" From https://github.com/mopp/dotfiles/blob/master/.vimrc
" Set <Leader> and <LocalLeader>.
let g:mapleader = ' '
nnoremap <silent> <Leader>w :<C-U>wall<CR>
" Slightly stolen from vim-unimpaired
nnoremap [p :set paste<cr>
nnoremap ]p :set nopaste<cr>
" More stolen from vim-unimpaired
" q is for (q)uickfix list
nnoremap ]q :cnext<cr>
nnoremap [q :cprev<cr>
nnoremap ]Q :cfirst<cr>
nnoremap [Q :clast<cr>
nnoremap [n :set number<cr>
nnoremap ]n :set nonumber<cr>
nnoremap [r :set relativenumber<cr>
nnoremap ]r :set norelativenumber<cr>
" tried [s and ]s but that conflicts
nnoremap [os :set spell<cr>
nnoremap ]os :set nospell<cr>
inoremap jj <C-[>
" Buffers {{{
" Since I use buffers so much, have an easier mapping for switching.
nnoremap <silent> ]b :bn<cr>
nnoremap <silent> [b :bp<cr>
" }}}
" Movement {{{
" Movements that ignore differences in visual v.s. actual lines
nnoremap j gj
nnoremap k gk
" The default mappings look for { or } on the first column, since most cpp
" files I edit don't use this K&R style, remap these to something somewhat
" useful.
nnoremap [[ ?{$<CR>:nohl<CR>
nnoremap ][ /{$<CR>:nohl<CR>
nnoremap ]] /}$<CR>:nohl<CR>
nnoremap [] ?}$<CR>:nohl<CR>
" }}}
" Commentary
nmap gC gcc
" }}}
" Search {{{
set hlsearch
set incsearch " Search incrementally.
" Turns off highlight using this key map
" map <C-c> :noh<cr>
" treats pattern as case insenstive when all small letters
set ignorecase smartcase
" }}}
" Indents {{{
set smartindent
set shiftwidth=2
set smarttab
set expandtab
" }}}
" opens $MYVIMRC for editing, or use :tabedit $MYVIMRC
:nmap <Leader>vim :edit $MYVIMRC<cr>
" autocommands {{{
augroup ngzhian
autocmd!
" Save everytime I exit insert mode
" autocmd InsertLeave * :silent w
" Turning off paste when escape insert mode.
autocmd InsertLeave * setlocal nopaste
" .vimrc {{{
autocmd FileType vim set foldmethod=marker
" source when vimrc is updated
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" }}}
" Git/Hg commit messages {{{
autocmd FileType gitcommit set spell colorcolumn=72
autocmd FileType hgcommit set spell colorcolumn=72
" }}}
" bashrc {{{
autocmd FileType sh set foldmethod=marker
" }}}
" rst {{{
autocmd FileType rst set spell
" }}}
" ocaml {{{
" autocmd FileType ocaml set rtp^="/usr/local/google/home/zhin/.opam/4.09.0/share/ocp-indent/vim"
" }}}
augroup END
" }}}
"
" Used to be NERDTree {{{
let g:netrw_banner = 0
nnoremap <leader>d :Vexplore<CR>
" }}}
" Vimux {{{
nnoremap <leader>vl :VimuxRunLastCommand<CR>
nnoremap <leader>vp :VimuxPromptCommand<CR>
" Runs the previous bash command in the runner pane
function! VimuxRunPrev()
call VimuxOpenRunner()
call VimuxSendKeys("C-p")
call VimuxSendKeys("Enter")
endfunction
nnoremap <leader>l :call VimuxRunPrev()<CR>
" }}}
" fzf {{{
" use fzf to replace ctrl-p
set rtp+=~/.fzf
nnoremap <C-p> :Files<CR>
nnoremap <leader>p :Files<CR>
nnoremap <leader>f :Files<CR>
" C-b is used to scroll window backwards, I usually use C-u for it.
" nnoremap <C-b> :Buffers<CR>
nnoremap <leader>b :Buffers<CR>
" search search history
nnoremap <leader>/ :History/<CR>
" search (e)x- commands history
nnoremap <leader>: :History:<CR>
nnoremap <leader>; :History:<CR>
" }}}
" EasyMotion {{{
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap S <Plug>(easymotion-overwin-f)
nmap <leader>s <Plug>(easymotion-overwin-f)
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" }}}
" For asyncomplete {{{
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<cr>"
if has('python3')
" Ctrl-y is used to accept a suggestion from the completion menu,
" with async complete, we use tab to change the selection.
let g:UltiSnipsExpandTrigger="<c-y>"
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#ultisnips#get_source_options({
\ 'name': 'ultisnips',
\ 'whitelist': ['*'],
\ 'completor': function('asyncomplete#sources#ultisnips#completor')
\ }))
endif
" }}}
" LSP {{{
if executable('clangd')
au User lsp_setup call lsp#register_server({
\ 'name': 'clangd',
\ 'cmd': {server_info->['clangd', '--background-index', '--clang-tidy']},
\ 'whitelist': ['c', 'cpp'],
\ })
endif
if executable('ocamllsp')
au User lsp_setup call lsp#register_server({
\ 'name': 'ocamllsp',
\ 'cmd': {server_info->['ocamllsp']},
\ 'whitelist': ['ocaml'],
\ })
endif
" From https://github.com/prabirshrestha/vim-lsp.
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=auto
" follow how gd works by default, with is go to local declaration
nmap <buffer> gd <plug>(lsp-declaration)
nmap <buffer> gD <plug>(lsp-definition)
" gr does some replacement of virtual characters, which I've never used.
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> <f2> <plug>(lsp-rename)
" refer to doc to add more commands
" TODO some other mapping?
nmap <buffer> <f3> <plug>(lsp-document-diagnostics)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
" gq is already the formatting motion, but let's reuse it.
" Since this is within a lsp install guard, it shouldn't affect the usual
" functioning of gq in, say, commit messages.
vnoremap <buffer> gq :<c-u>LspDocumentRangeFormatSync<cr>
nnoremap <buffer> gq :<c-u>LspDocumentFormatSync<cr>
" Might want this to be :LspWorkspaceSymbol, but try this out for now.
nnoremap <buffer> K :LspHover<cr>
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
let g:lsp_diagnostics_echo_cursor=1
" let g:lsp_diagnostics_float_cursor=1
" Logging to debug lsp
" let g:lsp_log_verbose = 1
" let g:lsp_log_file = expand('~/vim-lsp.log')
" }}}
" Misc helper functions copied from some place. {{{
" :VC map to view output of map in a buffer
command! -nargs=1 VC call ExecuteVimCommandAndViewOutput(<q-args>)
function! ExecuteVimCommandAndViewOutput(cmd)
redir @v
silent execute a:cmd
redir END
new
set buftype=nofile
put v
endfunction
" }}}
" {{{ Abberviations
abbreviate tf TurboFan
abbreviate lo Liftoff
abbreviate v8iwyu v8:7490
abbreviate v8clean v8:11384
abbreviate v8ship v8:11511
abbreviate v8relax v8:11583
abbreviate v8share v8:11589
" }}}
" set statusline=%<%F\ %m%r%h%w%y%{'['.(&fenc!=''?&fenc:&enc).']['.&fileformat.']'}%=%l/%L,%c%V%8P
" {{{ Syntax highlighting
" Some custom syntax to match tmux, originally from
" https://github.com/vim-airline/vim-airline-themes/blob/master/autoload/airline/themes/papercolor.vim
hi StatusLine cterm=bold ctermfg=240 ctermbg=255
hi StatusLineNC cterm=NONE ctermfg=255 ctermbg=24
" The separator color is slightly different from tmux, which is 31, not sure
" if that's what i want, let's try it and see.
hi VertSplit cterm=NONE ctermfg=250
hi ColorColumn ctermbg=255
hi Folded ctermfg=24 ctermbg=15
" }}}