-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
322 lines (264 loc) · 9.58 KB
/
init.vim
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
" set t_Co=8
set nocompatible
" colorscheme delek
call plug#begin('~/.vim/plugged')
" Plug 'mhinz/vim-signify'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'vito-c/jq.vim'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'nvie/vim-flake8'
Plug 'tpope/vim-commentary'
Plug 'justinmk/vim-dirvish'
Plug 'mbbill/undotree'
Plug 'luochen1990/rainbow'
Plug 'wlangstroth/vim-racket'
Plug 'katusk/vim-qkdb-syntax'
Plug 'cespare/vim-toml'
" Plug 'prabirshrestha/asyncomplete.vim'
" Plug 'prabirshrestha/async.vim'
" Plug 'prabirshrestha/vim-lsp'
" Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'rust-lang/rust.vim'
Plug 'OmniSharp/omnisharp-vim'
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Extensions to built-in LSP, for example, providing type inlay hints
Plug 'tjdevries/lsp_extensions.nvim'
" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'
Plug 'arcticicestudio/nord-vim'
Plug 'rafi/awesome-vim-colorschemes'
call plug#end()
colorscheme abstract
filetype plugin indent on
syntax on
set backspace=indent,eol,start
set mouse=a
set number
let mapleader = "\<Space>"
set directory=~/.vim/swapfiles//
set wildmenu
set wildignorecase
set ignorecase
set smartcase
" Use system clipboard
set clipboard=unnamedplus
" Don't lose undo history when switching buffers
set hidden
nnoremap <Leader>fs :w<CR>
nnoremap <Leader>gs :Gstatus<CR>
nnoremap <Leader>mgg :LspDefinition<CR>
nnoremap <Leader>mgG :LspPeekDefinition<CR>
nnoremap <Leader>mh :LspHover<CR>
nnoremap <Leader>mf :LspDocumentFormat<CR>
nnoremap <Leader>mR :LspRename<CR>
nnoremap <Leader>el :LspDocumentDiagnostics<CR>
nnoremap <Leader>ml :LspDocumentSymbol<CR>
nnoremap <Leader>mL :LspWorkspaceSymbol<CR>
nmap <Leader>bb :Buffers<CR>
nmap <Leader>ff :Files<CR>
nmap <Leader>ll :Lines<CR>
nmap <Leader>tt :BTags<CR>
nmap <Leader>ls :BLines<CR>
nmap <Leader>ar :Ranger<CR>
nnoremap <Leader>pf :CtrlPCurWD<CR>
nnoremap <Leader>bs :CtrlPBuffer<CR>
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
nnoremap <Leader>wj <C-W><C-J>
nnoremap <Leader>wk <C-W><C-K>
nnoremap <Leader>wl <C-W><C-L>
nnoremap <Leader>wh <C-W><C-H>
noremap <buffer> <silent> k gk
noremap <buffer> <silent> j gj
noremap <buffer> <silent> 0 g0
noremap <buffer> <silent> $ g$
onoremap <silent> j gj
onoremap <silent> k gk
map <Leader>b :silent !rust-watch notify<CR>
hi StatusLine cterm=bold ctermfg=7 ctermbg=6
hi StatusLineNC cterm=None ctermfg=1 ctermbg=8
hi VertSplit cterm=None ctermfg=8 ctermbg=8
hi LineNr ctermfg=4
hi Folded ctermbg=darkgray
" hi LspWarningHighlight cterm=underline
" " hi clear LspWarningHighlight
" hi LspErrorHighlight ctermfg=Red
" hi LspInformationHighlight ctermbg=DarkBlue
" hi LspHintHighlight ctermbg=Green
" hi Pmenu ctermbg=LightBlue
" hi LspHintText ctermbg=Red
" hi LspInformationText ctermbg=Red
" hi LspInformationLine ctermbg=Red
" hi LspHintLine ctermbg=Red
" hi LspErrorLine ctermbg=Red
" hi LspWarningText ctermfg=DarkYellow
" hi LspInformationText ctermfg=DarkBlue
" hi LspErrorText ctermfg=DarkRed
" hi LspErrorText ctermbg=Red
hi CursorLine cterm=NONE
set cursorline
let g:rainbow_active = 1
set t_ti=
set t_te=
if executable('rls')
au User lsp_setup call lsp#register_server({
\ 'name': 'rls',
\ 'cmd': {server_info->['rustup', 'run', 'stable', 'rls']},
\ 'workspace_config': {'rust': {'clippy_preference': 'on'}},
\ 'whitelist': ['rust'],
\ })
endif
let g:lsp_signs_enabled = 1 " enable signs
let g:lsp_diagnostics_echo_cursor = 1 " enable echo under cursor when in normal mode
let g:lsp_preview_float = 1
let g:lsp_signs_error = {'text': '●'}
let g:lsp_signs_warning = {'text': '●'}
let g:lsp_signs_hint = {'text': '●'}
let g:lsp_signs_information = {'text': '●'}
let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')
let g:ctrlp_custom_ignore = 'all_data'
"" gitgutter
nmap <Leader>gp <Plug>(GitGutterPrevHunk)
nmap <Leader>gn <Plug>(GitGutterNextHunk)
let g:gitgutter_override_sign_column_highlight = 1
let g:gitgutter_highlight_linenrs = 1
hi GitGutterAdd ctermfg=Green
hi GitGutterChange ctermfg=Yellow
hi GitGutterDelete ctermfg=Red
hi GitGutterChangeDelete ctermfg=Red
hi GitGutterAddLineNr ctermfg=Green
hi GitGutterChangeLineNr ctermfg=Yellow
hi GitGutterDeleteLineNr ctermfg=Red
hi GitGutterChangeDeleteLineNr ctermfg=Red
autocmd FileType rust setlocal omnifunc=lsp#omni#complete
autocmd FileType rust setlocal tabstop=4
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
nnoremap <Leader>gs :Gstatus<CR>
nnoremap <Leader>mgg :LspDefinition<CR>
nnoremap <Leader>mgG :LspPeekDefinition<CR>
nnoremap <Leader>mh :LspHover<CR>
nnoremap <Leader>mf :LspDocumentFormat<CR>
nnoremap <Leader>mR :LspRename<CR>
nnoremap <Leader>el :LspDocumentDiagnostics<CR>
nmap <Leader>bb :Buffers<CR>
nmap <Leader>ff :Files<CR>
nmap <Leader>ll :Lines<CR>
nmap <Leader>tt :BTags<CR>
nmap <Leader>ls :BLines<CR>
nmap <Leader>ar :Ranger<CR>
nnoremap <Leader>pf :CtrlPCurWD<CR>
nnoremap <Leader>bs :CtrlPBuffer<CR>
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
nnoremap <Leader>wj <C-W><C-J>
nnoremap <Leader>wk <C-W><C-K>
nnoremap <Leader>wl <C-W><C-L>
nnoremap <Leader>wh <C-W><C-H>
noremap <buffer> <silent> k gk
noremap <buffer> <silent> j gj
noremap <buffer> <silent> 0 g0
noremap <buffer> <silent> $ g$
onoremap <silent> j gj
onoremap <silent> k gk
map <Leader>b :silent !rust-watch notify<CR>
sign define LspDiagnosticsSignError text=E texthl=LspDiagnosticsError linehl= numhl=
sign define LspDiagnosticsSignWarning text=W texthl=LspDiagnosticsWarning linehl= numhl=
sign define LspDiagnosticsSignInformation text=I texthl=LspDiagnosticsInformation linehl= numhl=
sign define LspDiagnosticsSignHint text=H texthl=LspDiagnosticsHint linehl= numhl=
hi LspDiagnosticsError ctermfg=red
hi LspDiagnosticsWarning ctermfg=yellow
hi LspDiagnosticsInformation ctermfg=green
hi LspDiagnosticsHint ctermfg=blue
" hi LspDiagnosticsErrorFloat ctermfg=red ctermfg=green
" hi LspDiagnosticsDefaultHint ctermfg=red
hi LspDefaultInformation ctermfg=blue
hi LspDiagnosticsDefaultError ctermfg=red cterm=italic
hi LspDiagnosticsDefaultWarning ctermfg=yellow cterm=italic
hi LspDiagnosticsDefaultInformation ctermfg=green cterm=italic
hi LspDiagnosticsDefaultHint ctermfg=blue cterm=italic
" hi LspDiagnosticsVirtualTextError ctermfg=blue
" hi LspDiagnosticsVirtualTextWarning ctermfg=blue
" hi LspDiagnosticsVirtualTextInformation ctermfg=blue
" hi LspDiagnosticsVirtualTextHint ctermfg=blue
" hi LspDiagnosticsFloatingError ctermfg=green
" Set completeopt to have a better completion experience
" :help completeopt
" menuone: popup even when there's only one match
" noinsert: Do not insert text until a selection is made
" noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect
" Avoid showing extra messages when using completion
set shortmess+=c
" Configure LSP
" https://github.com/neovim/nvim-lspconfig#rust_analyzer
lua <<EOF
-- nvim_lsp object
local nvim_lsp = require'lspconfig'
-- function to attach completion when setting up lsp
local on_attach = function(client)
require'completion'.on_attach(client)
end
-- Enable rust_analyzer
nvim_lsp.rust_analyzer.setup({ on_attach=on_attach })
-- capabilities = {
-- textDocument = {
-- documentHighlight = {
-- dynamicRegistration = true
-- }
-- }
-- }
-- })
-- Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true,
signs = true,
update_in_insert = true,
}
)
EOF
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" use <Tab> as trigger keys
imap <Tab> <Plug>(completion_smart_tab)
imap <S-Tab> <Plug>(completion_smart_s_tab)
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gR <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gf <cmd>lua vim.lsp.buf.formatting()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()
hi LspReferenceText ctermbg=darkgrey gui=bold
hi LspReferenceRead ctermbg=darkgrey gui=bold
hi LspReferenceWrite ctermbg=darkgrey gui=bold
autocmd CursorHold * lua vim.lsp.buf.document_highlight()
autocmd CursorHoldI * lua vim.lsp.buf.document_highlight()
autocmd CursorMoved * lua vim.lsp.buf.clear_references()
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
set signcolumn=yes
hi LspTypeInlayHint ctermfg=darkgrey cterm=italic
" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = ' § ', highlight = "LspTypeInlayHint" }