-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
370 lines (356 loc) · 9.78 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
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)
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.autoindent = true
vim.opt.signcolumn = 'yes'
vim.opt.hlsearch = false
vim.opt.backup = false
vim.opt.showcmd = true
vim.opt.mouse = ''
vim.opt.cmdheight = 0
vim.opt.laststatus = 2
vim.opt.scrolloff = 12
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.shell = vim.fn.has('win32') == 1 and 'cmd' or 'zsh'
vim.opt.updatetime = 1000
vim.opt.cursorline = false
vim.opt.termguicolors = true
vim.opt.listchars = 'tab:» ,extends:›,precedes:‹,nbsp:#';
require('lazy').setup({
{
'navarasu/onedark.nvim',
opts = {
style = 'darker',
transparent = true
},
init = function()
local onedark = require('onedark')
onedark.load()
end
},
{
'folke/which-key.nvim',
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 1000
vim.g.mapleader = ' '
local set = vim.keymap.set
-- jk to cancel insert mode
set('i', 'jk', '<Esc>')
set('t', 'jk', '<C-\\><C-n>')
-- do not add to register with x, c or d
set('n', 'x', '"_x')
set('n', 'd', '"_d')
set('n', 'D', 'd')
set('n', 'c', '"_c')
set('n', 'C', 'c')
set('n', 'Y', '"+y')
set('v', 'x', '"_x')
set('v', 'd', '"_d')
set('v', 'D', 'd')
set('v', 'c', '"_c')
set('v', 'C', 'c')
set('v', 'Y', '"+y')
-- first level keybindings
set('n', '-', '<cmd>lua require("oil").open()<cr>', {
silent = true,
desc = 'Explore directory of current buffer',
})
-- which-key for maps that start with the leader key
local which = require('which-key')
which.setup {}
which.register({
['<leader>'] = {
Q = { '<cmd>bd!<cr>', 'Quit buffer (discard unsaved changes)' },
q = { '<cmd>w<cr><cmd>bd<cr>', 'Save and quit buffer' },
e = { '<cmd>Oil .<cr>', 'Explore project directory' },
r = { '<cmd>Telescope oldfiles<cr>', 'Open recent buffer' },
t = { '<cmd>term<cr>', 'Open new terminal buffer' },
y = { '<cmd>lua vim.lsp.buf.format()<cr>', 'Format document' },
u = { '<cmd>lua vim.lsp.buf.references()<cr>', 'List references' },
i = { '<cmd>lua vim.lsp.buf.rename()<cr>', 'Rename symbol' },
-- o = {},
-- p = {},
a = { '<cmd>wa<cr>', 'Save all buffers' },
s = { '<cmd>w<cr>', 'Save buffer' },
d = { '<cmd>lua vim.lsp.buf.definition()<cr>', 'Jump to definition' },
f = { '<cmd>Telescope find_files<cr>', 'Search file in current directory' },
g = { '<cmd>Telescope live_grep<cr>', 'Search file content in current directory' },
h = { '<cmd>lua vim.lsp.buf.hover()<cr>', 'Show documentation' },
j = { '<cmd>Gitsigns next_hunk<cr>', 'Jump to next git hunk' },
k = { '<cmd>Gitsigns prev_hunk<cr>', 'Jump to previous git hunk' },
-- l = {},
z = { '<cmd>lua vim.lsp.buf.code_action()<cr>', 'Show possible actions' },
x = { '<cmd>lua vim.diagnostic.goto_prev()<cr>', 'Jump to previous diagnostic' },
c = { '<cmd>lua vim.diagnostic.goto_next()<cr>', 'Jump to next diagnostic' },
v = { '<cmd>Telescope diagnostics<cr>', 'List diagnostics' },
b = { '<cmd>Telescope buffers<cr>', 'List buffers' },
n = { '<cmd>G<cr><C-w>o', 'Open git client' },
m = { '<cmd>Telescope resume<cr>', 'Back to Telescope panel' },
w = {
name = '+windows',
s = { '<cmd>split<cr>', 'Create new window below' },
v = { '<cmd>vsplit<cr>', 'Create new window to the right' },
h = { '<C-w>h', 'Navigate to window in the left' },
j = { '<C-w>j', 'Navigate to window below' },
k = { '<C-w>k', 'Navigate to window above' },
l = { '<C-w>l', 'Navigate to window in the right' },
o = { '<C-w>o', 'Close all other windows' },
c = { '<C-w>c', 'Close this window' },
},
},
})
end
},
{
'neovim/nvim-lspconfig',
init = function()
local lsp = require('lspconfig')
lsp.tsserver.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end
}
lsp.eslint.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> :EslintFixAll]]
vim.api.nvim_command [[augroup END]]
end
}
lsp.jsonls.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end
}
lsp.lua_ls.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end,
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false
}
}
}
}
lsp.rust_analyzer.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end,
settings = {
['rust-analyzer'] = {
procMacro = {
enable = true
},
diagnostics = {
enable = true,
disabled = { 'unresolved-proc-macro' },
enableExperimental = true,
}
}
}
}
lsp.terraformls.setup {}
lsp.tflint.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end
}
lsp.yamlls.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end
}
lsp.svelte.setup {
on_attach = function()
vim.api.nvim_command [[augroup Format]]
vim.api.nvim_command [[autocmd! * <buffer>]]
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]]
vim.api.nvim_command [[augroup END]]
end
}
end
},
{
'nvim-telescope/telescope.nvim',
dependencies = { 'nvim-lua/plenary.nvim' },
init = function()
local telescope = require('telescope')
local actions = require('telescope.actions')
telescope.setup {
pickers = {
find_files = {
theme = 'ivy',
layout_config = {
height = 30
}
},
live_grep = {
theme = 'ivy',
layout_config = {
height = 30
}
},
oldfiles = {
theme = 'ivy',
layout_config = {
height = 30
}
},
buffers = {
theme = 'ivy',
layout_config = {
height = 30
},
sort_mru = true,
on_complete = { function() vim.cmd "stopinsert" end },
mappings = {
n = {
q = actions.delete_buffer
}
},
},
},
}
end
},
{
'hrsh7th/nvim-cmp',
dependencies = {
'L3MON4D3/LuaSnip',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-nvim-lsp',
},
init = function()
local luasnip = require('luasnip')
local cmp = require('cmp')
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
mapping = cmp.mapping.preset.insert {
['<C-Space>'] = cmp.mapping.complete(),
['<Return>'] = 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 = cmp.config.sources {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' }
}
}
end
},
{
'nvim-lualine/lualine.nvim',
opts = {
options = {
icons_enabled = true,
theme = 'tokyonight'
},
sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch' },
lualine_c = { { 'filename', path = 1 } },
lualine_x = { 'diagnostics' },
lualine_y = {},
lualine_z = {}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { { 'filename', path = 1 } },
lualine_x = {},
lualine_y = {},
lualine_z = {}
}
}
},
{
'stevearc/oil.nvim',
opts = {
columns = {
'icon',
},
view_options = {
show_hidden = true,
},
},
dependencies = { 'nvim-tree/nvim-web-devicons' },
},
{
'folke/flash.nvim',
opts = {},
keys = {
{ 's', mode = { 'n', 'x', 'o' }, function() require('flash').jump() end, desc = 'Flash' },
{ 'S', mode = { 'n', 'x', 'o' }, function() require('flash').treesitter() end, desc = 'Flash Treesitter' },
{ '<c-s>', mode = { 'c' }, function() require('flash').toggle() end, desc = 'Toggle Flash Search' },
}
},
{
'lewis6991/gitsigns.nvim',
opts = {}
},
'tpope/vim-fugitive',
'tpope/vim-commentary',
'sheerun/vim-polyglot',
})