-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
414 lines (355 loc) · 13 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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
" This is an example on how rust-analyzer can be configure using rust-tools
" Prerequisites:
" - neovim >= 0.5
" - rust-analyzer: https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary
" Steps:
" - :PlugInstall
" - Restart
call plug#begin('~/.vim/plugged')
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
Plug 'tami5/lspsaga.nvim'
Plug 'williamboman/nvim-lsp-installer'
" Autocompletion framework
Plug 'hrsh7th/nvim-cmp'
" cmp LSP completion
Plug 'hrsh7th/cmp-nvim-lsp'
" cmp Snippet completion
Plug 'hrsh7th/cmp-vsnip'
" cmp Path completion
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
" See hrsh7th other plugins for more great completion sources!
" Adds extra functionality over rust analyzer
Plug 'simrat39/rust-tools.nvim'
Plug 'simrat39/symbols-outline.nvim'
" Snippet engine
Plug 'hrsh7th/vim-vsnip'
" Optional
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-lua/lsp-status.nvim'
Plug 'ojroques/nvim-hardline'
Plug 'j-hui/fidget.nvim'
Plug 'lewis6991/gitsigns.nvim'
Plug 'tpope/vim-surround'
Plug 'folke/trouble.nvim'
" If you want to display icons, then use one of these plugins:
Plug 'kyazdani42/nvim-web-devicons' " lua
" Some color scheme other then default
Plug 'iCyMind/NeoSolarized'
call plug#end()
set termguicolors
set background=light
colorscheme NeoSolarized
" 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 through rust-tools.nvim plugin.
" rust-tools will configure and enable certain LSP features for us.
" See https://github.com/simrat39/rust-tools.nvim#configuration
lua <<EOF
-- setup rust-tools
local lsp_status = require('lsp-status')
lsp_status.register_progress()
local lspconfig = require('lspconfig')
lspconfig.rust_analyzer.setup({
on_attach = lsp_status.on_attach,
capabilities = lsp_status.capabilities
})
local lsp_installer = require("nvim-lsp-installer")
lsp_installer.settings({
ui = {
icons = {
server_installed = "✓",
server_pending = "➜",
server_uninstalled = "✗"
}
}
})
local lsp_installer = require("nvim-lsp-installer")
-- Include the servers you want to have installed by default below
local servers = {
"bashls",
"gopls",
"rust_analyzer",
"yamlls",
"vimls"
}
for _, name in pairs(servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found and not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
lsp_installer.on_server_ready(function(server)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
}
}
capabilities = vim.tbl_extend('keep', capabilities or {}, lsp_status.capabilities)
capabilities.experimental = {}
capabilities.experimental.hoverActions = true
local opts = {
tools = {
autoSetHints = true,
hover_with_actions = true,
runnables = {
use_telescope = true
},
debuggables = {
use_telescope = true
},
inlay_hints = {
show_parameter_hints = true,
parameter_hints_prefix = "↢ ",
other_hints_prefix = "↣ ",
highlight = "RustInlayHint",
},
hover_actions = {
border = {
{"╭", "FloatBorder"}, {"─", "FloatBorder"},
{"╮", "FloatBorder"}, {"│", "FloatBorder"},
{"╯", "FloatBorder"}, {"─", "FloatBorder"},
{"╰", "FloatBorder"}, {"│", "FloatBorder"}
},
-- whether the hover action window gets automatically focused
auto_focus = true
},
crate_graph = {
-- Backend used for displaying the graph
-- see: https://graphviz.org/docs/outputs/
-- default: x11
backend = "png",
-- where to store the output, nil for no output stored (relative
-- path from pwd)
-- default: nil
output = nil,
-- true for all crates.io and external crates, false only the local
-- crates
-- default: true
full = true,
-- enabled_graphviz_backends = {
-- "bmp", "cgimage", "canon", "dot", "gv", "xdot", "xdot1.2", "xdot1.4",
-- "eps", "exr", "fig", "gd", "gd2", "gif", "gtk", "ico", "cmap", "ismap",
-- "imap", "cmapx", "imap_np", "cmapx_np", "jpg", "jpeg", "jpe", "jp2",
-- "json", "json0", "dot_json", "xdot_json", "pdf", "pic", "pct", "pict",
-- "plain", "plain-ext", "png", "pov", "ps", "ps2", "psd", "sgi", "svg",
-- "svgz", "tga", "tiff", "tif", "tk", "vml", "vmlz", "wbmp", "webp", "xlib",
-- "x11"
-- }
}
},
server = { -- setup rust_analyzer
on_attach = lsp_on_attach,
capabilities = capabilities,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy"
},
}
}
},
-- dap = {
-- adapter = {
-- type = 'executable',
-- command = 'lldb-vscode',
-- name = "rt_lldb"
-- }
-- }
}
if server.name == "rust_analyzer" then
-- Initialize the LSP via rust-tools instead
require("rust-tools").setup {
-- The "server" property provided in rust-tools setup function are the
-- settings rust-tools will provide to lspconfig during init.
-- We merge the necessary settings from nvim-lsp-installer (server:get_default_options())
-- with the user's own settings (opts).
server = vim.tbl_deep_extend("force", server:get_default_options(), opts),
}
server:attach_buffers()
-- Only if standalone support is needed
require("rust-tools").start_standalone_if_required()
else
server:setup(opts)
end
end)
-- setup rust-tools end
EOF
let mapleader = ','
" Code navigation shortcuts
" as found in :help lsp
"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><leader>n <cmd>lua vim.lsp.buf.rename()<CR>
" Quick-fix
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent>ff <cmd>lua vim.lsp.buf.formatting()<cr>
" Setup Completion
" See https://github.com/hrsh7th/nvim-cmp#basic-configuration
lua <<EOF
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})
EOF
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hover (Disabled because it's the same as
" <leader>cd <leader>cc from lspsaga, we should choose between the two
" autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.diagnostic.goto_next()<CR>
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
lua require('gitsigns').setup()
set statusline+=%{get(b:,'gitsigns_status','')}
lua require('hardline').setup {}
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
require'nvim-web-devicons'.setup {
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true;
}
local saga = require 'lspsaga'
saga.init_lsp_saga()
require("trouble").setup {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
EOF
nnoremap <silent>gh <cmd>lua require'lspsaga.provider'.lsp_finder()<CR>
nnoremap <silent><leader>ca <cmd>lua require('lspsaga.codeaction').code_action()<CR>
vnoremap <silent><leader>ca :<C-U>lua require('lspsaga.codeaction').range_code_action()<CR>
nnoremap <silent>K <cmd>lua require('lspsaga.hover').render_hover_doc()<CR>
nnoremap <silent>gs <cmd>lua require('lspsaga.signaturehelp').signature_help()<CR>
nnoremap <silent>gr <cmd>lua require('lspsaga.rename').rename()<CR>
"nnoremap <silent>gd <cmd>lua require'lspsaga.provider'.preview_definition()<CR>
nnoremap <silent><leader>cd <cmd>lua require'lspsaga.diagnostic'.show_line_diagnostics()<CR>
nnoremap <silent><leader>cc <cmd>lua require'lspsaga.diagnostic'.show_cursor_diagnostics()<CR>
nnoremap <silent> [e <cmd>lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_prev()<CR>
nnoremap <silent> ]e <cmd>lua require'lspsaga.diagnostic'.lsp_jump_diagnostic_next()<CR>
lua <<EOF
-- init.lua
vim.g.symbols_outline = {
highlight_hovered_item = true,
show_guides = true,
auto_preview = true,
position = 'right',
relative_width = true,
width = 25,
auto_close = false,
show_numbers = false,
show_relative_numbers = false,
show_symbol_details = true,
preview_bg_highlight = 'Pmenu',
keymaps = { -- These keymaps can be a string or a table for multiple keys
close = {"<Esc>", "q"},
goto_location = "<Cr>",
focus_location = "o",
hover_symbol = "<C-space>",
toggle_preview = "K",
rename_symbol = "r",
code_actions = "a",
},
lsp_blacklist = {},
symbol_blacklist = {},
symbols = {
File = {icon = "", hl = "TSURI"},
Module = {icon = "", hl = "TSNamespace"},
Namespace = {icon = "", hl = "TSNamespace"},
Package = {icon = "", hl = "TSNamespace"},
Class = {icon = "𝓒", hl = "TSType"},
Method = {icon = "ƒ", hl = "TSMethod"},
Property = {icon = "", hl = "TSMethod"},
Field = {icon = "", hl = "TSField"},
Constructor = {icon = "", hl = "TSConstructor"},
Enum = {icon = "ℰ", hl = "TSType"},
Interface = {icon = "ﰮ", hl = "TSType"},
Function = {icon = "", hl = "TSFunction"},
Variable = {icon = "", hl = "TSConstant"},
Constant = {icon = "", hl = "TSConstant"},
String = {icon = "𝓐", hl = "TSString"},
Number = {icon = "#", hl = "TSNumber"},
Boolean = {icon = "⊨", hl = "TSBoolean"},
Array = {icon = "", hl = "TSConstant"},
Object = {icon = "⦿", hl = "TSType"},
Key = {icon = "🔐", hl = "TSType"},
Null = {icon = "NULL", hl = "TSType"},
EnumMember = {icon = "", hl = "TSField"},
Struct = {icon = "𝓢", hl = "TSType"},
Event = {icon = "🗲", hl = "TSType"},
Operator = {icon = "+", hl = "TSOperator"},
TypeParameter = {icon = "𝙏", hl = "TSParameter"}
}
}
EOF
lua require"fidget".setup{}