-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
417 lines (376 loc) · 12.6 KB
/
init.lua
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
415
416
417
-- Install package manager
local cmd = vim.cmd
local map = vim.keymap.set
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system { 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', '--branch=stable', lazypath }
end
vim.opt.rtp:prepend(lazypath)
require'settings'
-- require'terraform'
-- Add plugins
require('lazy').setup({
'junegunn/fzf',
'preservim/nerdtree',
'vim-syntastic/syntastic',
'hashivim/vim-terraform',
'tpope/vim-fugitive', -- Git commands in nvim
'tpope/vim-rhubarb', -- Fugitive-companion to interact with github
'numToStr/Comment.nvim', -- "gc" to comment visual regions/lines
'stevearc/oil.nvim', -- More modern netrw
'navarasu/onedark.nvim', -- Colorscheme
'morhetz/gruvbox',
'nvim-lualine/lualine.nvim', -- Fancier statusline
-- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim',
-- Add git related info in the signs columns and popups
'lewis6991/gitsigns.nvim',
'nvim-treesitter/nvim-treesitter', -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter-textobjects', -- Additional textobjects for treesitter
'neovim/nvim-lspconfig', -- Collection of configurations for built-in LSP client
'williamboman/mason.nvim', -- Automatically install LSPs to stdpath for neovim
'williamboman/mason-lspconfig.nvim', -- ibid
'folke/neodev.nvim', -- Lua language server configuration for nvim
-- https://smarttech101.com/nvim-lsp-autocompletion-mapping-snippets-fuzzy-search/#:~:text=Nvim%20lsp%20autocompletion%20helps%20you,memorizing%20too%20much%20programming%20jargon.
'SirVer/ultisnips',
'honza/vim-snippets',
{ -- Autocompletion
'hrsh7th/nvim-cmp',
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' },
},
-- Fuzzy Finder (files, lsp, etc)
{ 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } },
{
'nvim-telescope/telescope-fzf-native.nvim',
-- NOTE: If you have trouble with this installation, refer to the README for telescope-fzf-native.
build = 'make',
},
'derekwyatt/vim-scala',
{'scalameta/nvim-metals',
dependencies = { 'nvim-lua/plenary.nvim', 'mfussenegger/nvim-dap'}
}
})
-- Configure UltiSnips
vim.cmd([[
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
]])
--Set highlight on search
vim.o.hlsearch = false
--Make line numbers default
vim.wo.number = true
--Enable mouse mode
vim.o.mouse = 'a'
--Enable break indent
vim.o.breakindent = true
--Save undo history
vim.opt.undofile = true
--Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 250
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
--Set colorscheme (order is important here)
vim.o.termguicolors = true
vim.cmd.colorscheme 'gruvbox'
--Set statusbar
require('lualine').setup {
options = {
icons_enabled = false,
theme = 'gruvbox',
component_separators = '|',
section_separators = '',
},
}
--Enable Comment.nvim
require('Comment').setup()
--Remap space as leader key
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
--Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Highlight on yank
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
})
--Disable numbers in terminal mode
require('indent_blankline').setup {
char = '┊',
filetype_exclude = { 'help' },
buftype_exclude = { 'terminal', 'nofile' },
show_trailing_blankline_indent = false,
}
-- Gitsigns
require('gitsigns').setup {
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '‾' },
changedelete = { text = '~' },
},
on_attach = function(bufnr)
vim.keymap.set('n', '[c', require('gitsigns').prev_hunk, { buffer = bufnr })
vim.keymap.set('n', ']c', require('gitsigns').next_hunk, { buffer = bufnr })
end,
}
-- Oil
require('oil').setup()
vim.keymap.set('n', '-', function() require('oil').open() end, { desc = 'Open parent directory' })
-- Telescope
require('telescope').setup {
defaults = {
mappings = {
i = {
['<C-u>'] = false,
['<C-d>'] = false,
},
},
},
}
-- Enable telescope fzf native
require('telescope').load_extension 'fzf'
--Add leader shortcuts
vim.keymap.set('n', '<leader><space>', function() require('telescope.builtin').buffers { sort_lastused = true } end)
vim.keymap.set('n', '<leader>sf', function() require('telescope.builtin').find_files { previewer = false } end)
vim.keymap.set('n', '<leader>sb', function() require('telescope.builtin').current_buffer_fuzzy_find() end)
vim.keymap.set('n', '<leader>sh', function() require('telescope.builtin').help_tags() end)
vim.keymap.set('n', '<leader>st', function() require('telescope.builtin').tags() end)
vim.keymap.set('n', '<leader>sd', function() require('telescope.builtin').grep_string() end)
vim.keymap.set('n', '<leader>sp', function() require('telescope.builtin').live_grep() end)
vim.keymap.set('n', '<leader>?', function() require('telescope.builtin').oldfiles() end)
-- Treesitter configuration
-- Parsers must be installed manually via :TSInstall
require('nvim-treesitter.configs').setup {
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "scala", "rust",
"typescript", "javascript", "bash", "sql" },
highlight = {
enable = true, -- false will disable the whole extension
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
},
indent = {
enable = true,
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
},
}
-- Diagnostic settings
vim.diagnostic.config {
virtual_text = false,
update_in_insert = true,
}
-- Diagnostic keymaps
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
vim.keymap.set('n', '<leader>Q', vim.diagnostic.setqflist)
-- LSP settings
require('mason').setup {}
require('mason-lspconfig').setup()
-- Add nvim-lspconfig plugin
local lspconfig = require 'lspconfig'
local on_attach = function(_, bufnr)
local attach_opts = { silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, attach_opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, attach_opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, attach_opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, attach_opts)
vim.keymap.set('n', '<C-s>', vim.lsp.buf.signature_help, attach_opts)
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, attach_opts)
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, attach_opts)
vim.keymap.set('n', '<leader>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, attach_opts)
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, attach_opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, attach_opts)
vim.keymap.set('n', 'so', require('telescope.builtin').lsp_references, attach_opts)
end
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Enable the following language servers
local servers = { 'terraformls', 'tflint', 'vimls' }
-- , 'rust_analyzer', 'scala', 'clangd', 'rust_analyzer', 'tsserver' }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
}
end
lspconfig.rust_analyzer.setup {
settings = {
['rust-analyzer'] = {},
},
}
require('neodev').setup {}
lspconfig.lua_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
},
},
}
-- nvim-cmp setup
local cmp = require 'cmp'
local luasnip = require 'luasnip'
luasnip.config.setup {}
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
-- vim: ts=2 sts=2 sw=2 et
----------------------------------
-- LSP Setup ---------------------
----------------------------------
local metals_config = require('metals').bare_config()
-- Example of settings
metals_config.settings = {
showImplicitArguments = true,
excludedPackages = {
"akka.actor.typed.javadsl",
"com.github.swagger.akka.javadsl"
}
}
-- *READ THIS*
-- I *highly* recommend setting statusBarProvider to true, however if you do,
-- you *have* to have a setting to display this in your statusline or else
-- you'll not see any messages from metals. There is more info in the help
-- docs about this
metals_config.init_options.statusBarProvider = "on"
-- Example if you are using cmp how to make sure the correct capabilities for snippets are set
metals_config.capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Debug settings if you're using nvim-dap
local dap = require("dap")
dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "RunOrTest",
metals = {
runType = "runOrTestFile",
--args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example
},
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = {
runType = "testTarget",
},
},
}
metals_config.on_attach = function(client, bufnr)
require("metals").setup_dap()
end
-- Autocmd that will actually be in charging of starting the whole thing
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
-- NOTE: You may or may not want java included here. You will need it if you
-- want basic Java support but it may also conflict if you are using
-- something like nvim-jdtls which also works on a java filetype autocmd.
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})