-
Notifications
You must be signed in to change notification settings - Fork 6
/
init.lua
506 lines (461 loc) · 17.1 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
-- https://neovim.io/doc/user/lua-guide.html#lua-guide
local root_names = { '.git', '.envrc' }
local root_cache = {}
local function get_buffer_path()
local path = vim.api.nvim_buf_get_name(0)
return path ~= '' and vim.fs.dirname(path) or nil
end
local function find_root_directory(path)
return vim.fs.find(root_names, { path = path, upward = true })[1]
end
local function set_root()
local path = get_buffer_path()
if not path then return end
local root = root_cache[path] or vim.fs.dirname(find_root_directory(path))
if root then
root_cache[path] = root
vim.fn.chdir(root)
vim.cmd('DirenvExport')
end
end
local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {})
vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root })
-- Function to go to the last known cursor position
local function goto_last_position()
if vim.fn.line("'\"") >= 1 and vim.fn.line("'\"") <= vim.fn.line("$") and not vim.bo.filetype:match('commit') then
vim.cmd('normal! g`"')
end
end
-- Set an autocommand to go to the last known cursor position on BufReadPost event
vim.api.nvim_create_autocmd('BufReadPost', {
callback = goto_last_position
})
-- deps
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.api.nvim_create_autocmd("BufEnter", {
desc = "Disable automatic comment insertion",
group = vim.api.nvim_create_augroup("AutoComment", {}),
callback = function()
vim.opt_local.formatoptions:remove({ "c", "r", "o" })
end,
})
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- history
vim.opt.undofile = true
vim.opt.showmode = false
vim.opt.laststatus = 2
vim.opt.signcolumn = "yes"
vim.opt.number = true
vim.opt.title = true
-- tabs
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.tabstop = 2
vim.opt.expandtab = true
-- delays
vim.opt.updatetime = 250
vim.opt.timeoutlen = 400
-- search
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.gdefault = true
vim.opt.shortmess = "AIT"
-- windows
vim.opt.splitright = true
vim.opt.splitbelow = true
vim.opt.list = true
vim.opt.listchars = { nbsp = "¬", tab = ">•", extends = "»", precedes = "«", trail = "¶" }
vim.opt.clipboard = "unnamedplus"
vim.g.mapleader = " "
vim.keymap.set('n', '<esc>', ':nohlsearch<cr>')
vim.keymap.set('n', '<leader>w', ":write<cr>")
vim.keymap.set('n', ";", ":")
vim.keymap.set('n', "<leader>y", ":%y+<cr>")
vim.keymap.set('n', '<leader>t', ":NvimTreeToggle<cr>")
vim.keymap.set('n', '<leader>f', ":NvimTreeFindFile<cr>")
vim.keymap.set('n', '<leader>c', ':normal gcc<CR>', { desc = 'Toggle comment line' })
vim.keymap.set('v', '<leader>c', '<Esc>:normal gvgc<CR>', { desc = 'Toggle comment block' })
require("lazy").setup({
{
"norcalli/nvim-colorizer.lua",
config = function()
vim.opt.termguicolors = true
require 'colorizer'.setup()
end,
},
"tpope/vim-fugitive",
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup()
end
},
"sirtaj/vim-openscad",
"nvim-tree/nvim-tree.lua",
{
"nvim-telescope/telescope.nvim",
dependencies = { 'nvim-lua/plenary.nvim' }
},
"lukas-reineke/indent-blankline.nvim",
"nvim-lualine/lualine.nvim",
-- direnv
{
"direnv/direnv.vim",
init = function()
vim.g.direnv_silent_load = true
local group = vim.api.nvim_create_augroup("DirenvLoaded", { clear = true })
vim.api.nvim_create_autocmd({ "User" }, {
group = group,
pattern = "DirenvLoaded",
callback = function()
if vim.cmd.LspRestart ~= nil then
vim.cmd.LspStart()
end
end
})
end
},
{
"ggandor/leap.nvim",
config = function() require("leap").create_default_mappings() end,
},
-- lsp
"neovim/nvim-lspconfig",
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
}
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = {
ensure_installed = {
"lua",
"html",
"markdown",
"elixir",
"eex",
"heex",
"rust",
"javascript",
"css",
"dockerfile",
"css",
"json",
"nix"
},
auto_install = true,
highlight = { enable = true },
indent = { enable = true }
},
config = function(_, opts)
require('nvim-treesitter.install').prefer_git = true
require('nvim-treesitter.configs').setup(opts)
end
},
-- themes
{
"ksevelyar/joker.vim",
-- dir = "~/code/joker.vim",
lazy = false,
priority = 1000,
config = function()
vim.cmd.colorscheme("joker")
end,
},
"rebelot/kanagawa.nvim"
})
-- # LSP
local lspconfig = require('lspconfig')
-- ## CMP
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } -- cmp integration
local cmp = require 'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end
},
mapping = {
['<Down>'] = cmp.mapping.select_next_item(),
['<Up>'] = cmp.mapping.select_prev_item(),
['<CR>'] = cmp.mapping.confirm()
},
sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vsnip' } }, { { name = 'buffer' } })
})
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local silent = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, silent)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, silent)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, silent)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, silent)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(_, bufnr)
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufsilent = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufsilent)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufsilent)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufsilent)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufsilent)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufsilent)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufsilent)
vim.keymap.set('n', '<space>re', vim.lsp.buf.rename, bufsilent)
vim.keymap.set('n', '<space>a', vim.lsp.buf.code_action, bufsilent)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufsilent)
vim.keymap.set('n', '<space>=', function() vim.lsp.buf.format { async = true } end, bufsilent)
vim.keymap.set('n', '<leader>h', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end)
end
lspconfig.rust_analyzer.setup {
autostart = { false },
on_attach = on_attach,
capabilities = capabilities
}
lspconfig.elixirls.setup {
autostart = { false },
on_attach = on_attach,
cmd = { "elixir-ls" },
capabilities = capabilities
}
-- npm install -g typescript typescript-language-server
lspconfig.ts_ls.setup {
on_attach = on_attach,
capabilities = capabilities
}
lspconfig.nil_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
['nil'] = {
formatting = {
command = { "alejandra" }
}
}
}
}
lspconfig.eslint.setup {
on_attach = function(client)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
client.server_capabilities.completion = false
end
}
lspconfig.lua_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
}
-- # lualine
require 'lualine'.setup {
options = {
icons_enabled = true,
component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' },
always_divide_middle = false
},
sections = {
lualine_a = {
{ 'filename', symbols = { modified = ' + ', readonly = ' ', unnamed = 'No Name' } }
},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {
{ 'diagnostics', symbols = { error = '● ', warn = '● ', info = '● ', hint = '● ' } }
},
lualine_z = { 'branch' }
},
inactive_sections = {
lualine_a = {
{ 'filename', symbols = { modified = ' + ', readonly = ' ', unnamed = 'No Name' } }
},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = {}
}
-- # nvim-tree
local function on_nvim_tree_attach(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- Default mappings. Feel free to modify or remove as you wish.
vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, opts('CD'))
vim.keymap.set('n', '<C-e>', api.node.open.replace_tree_buffer, opts('Open: In Place'))
vim.keymap.set('n', '<C-k>', api.node.show_info_popup, opts('Info'))
vim.keymap.set('n', '<C-r>', api.fs.rename_sub, opts('Rename: Omit Filename'))
vim.keymap.set('n', '<C-t>', api.node.open.tab, opts('Open: New Tab'))
vim.keymap.set('n', '<C-v>', api.node.open.vertical, opts('Open: Vertical Split'))
vim.keymap.set('n', '<C-x>', api.node.open.horizontal, opts('Open: Horizontal Split'))
vim.keymap.set('n', '<BS>', api.node.navigate.parent_close, opts('Close Directory'))
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', '<Tab>', api.node.open.preview, opts('Open Preview'))
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
vim.keymap.set('n', '.', api.node.run.cmd, opts('Run Command'))
vim.keymap.set('n', '-', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
vim.keymap.set('n', 'bmv', api.marks.bulk.move, opts('Move Bookmarked'))
vim.keymap.set('n', 'B', api.tree.toggle_no_buffer_filter, opts('Toggle No Buffer'))
vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
vim.keymap.set('n', 'C', api.tree.toggle_git_clean_filter, opts('Toggle Git Clean'))
vim.keymap.set('n', '[c', api.node.navigate.git.prev, opts('Prev Git'))
vim.keymap.set('n', ']c', api.node.navigate.git.next, opts('Next Git'))
vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
vim.keymap.set('n', 'D', api.fs.trash, opts('Trash'))
vim.keymap.set('n', 'E', api.tree.expand_all, opts('Expand All'))
vim.keymap.set('n', 'e', api.fs.rename_basename, opts('Rename: Basename'))
vim.keymap.set('n', ']e', api.node.navigate.diagnostics.next, opts('Next Diagnostic'))
vim.keymap.set('n', '[e', api.node.navigate.diagnostics.prev, opts('Prev Diagnostic'))
vim.keymap.set('n', 'F', api.live_filter.clear, opts('Clean Filter'))
vim.keymap.set('n', 'f', api.live_filter.start, opts('Filter'))
vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help'))
vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Dotfiles'))
vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Git Ignore'))
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))
vim.keymap.set('n', 'K', api.node.navigate.sibling.first, opts('First Sibling'))
vim.keymap.set('n', 'm', api.marks.toggle, opts('Toggle Bookmark'))
vim.keymap.set('n', 'o', api.node.open.edit, opts('Open'))
vim.keymap.set('n', 'O', api.node.open.no_window_picker, opts('Open: No Window Picker'))
vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
vim.keymap.set('n', 'P', api.node.navigate.parent, opts('Parent Directory'))
vim.keymap.set('n', 'q', api.tree.close, opts('Close'))
vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
vim.keymap.set('n', 'R', api.tree.reload, opts('Refresh'))
vim.keymap.set('n', 's', api.node.run.system, opts('Run System'))
vim.keymap.set('n', 'S', api.tree.search_node, opts('Search'))
vim.keymap.set('n', 'U', api.tree.toggle_custom_filter, opts('Toggle Hidden'))
vim.keymap.set('n', 'W', api.tree.collapse_all, opts('Collapse'))
vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Relative Path'))
vim.keymap.set('n', '<2-LeftMouse>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', '<2-RightMouse>', api.tree.change_root_to_node, opts('CD'))
-- Mappings migrated from view.mappings.list
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', 'o', api.node.open.edit, opts('Open'))
vim.keymap.set('n', '<2-LeftMouse>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', 'g', api.tree.change_root_to_node, opts('CD'))
vim.keymap.set('n', '<C-v>', api.node.open.vertical, opts('Open: Vertical Split'))
vim.keymap.set('n', '<C-x>', api.node.open.horizontal, opts('Open: Horizontal Split'))
vim.keymap.set('n', '<C-t>', api.node.open.tab, opts('Open: New Tab'))
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
vim.keymap.set('n', 'P', api.node.navigate.parent, opts('Parent Directory'))
vim.keymap.set('n', '<BS>', api.node.navigate.parent_close, opts('Close Directory'))
vim.keymap.set('n', '<Tab>', api.node.open.preview, opts('Open Preview'))
vim.keymap.set('n', 'K', api.node.navigate.sibling.first, opts('First Sibling'))
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Dotfiles'))
vim.keymap.set('n', 'R', api.tree.reload, opts('Refresh'))
vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
vim.keymap.set('n', 'D', api.fs.trash, opts('Trash'))
vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
vim.keymap.set('n', '<C-r>', api.fs.rename_sub, opts('Rename: Omit Filename'))
vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Relative Path'))
vim.keymap.set('n', '<Space>y', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
vim.keymap.set('n', '[c', api.node.navigate.git.prev, opts('Prev Git'))
vim.keymap.set('n', ']c', api.node.navigate.git.next, opts('Next Git'))
vim.keymap.set('n', 'u', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', 's', api.node.run.system, opts('Run System'))
vim.keymap.set('n', 'q', api.tree.close, opts('Close'))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end
require 'nvim-tree'.setup {
on_attach = on_nvim_tree_attach,
view = {
side = 'left',
number = false,
relativenumber = false,
signcolumn = "yes",
},
renderer = {
icons = { show = { file = false, folder = true, folder_arrow = false, git = true } }
},
actions = {
open_file = { quit_on_open = false, resize_window = false, window_picker = { enable = false } }
}
}
-- # telescope
require 'telescope'.setup {
defaults = {
file_ignore_patterns = { "^./.git/" },
layout_config = {
width = 0.98,
height = 0.98
},
},
pickers = {
find_files = {
hidden = true
}
}
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader><leader>', builtin.find_files, {})
vim.keymap.set('n', '<leader>r', builtin.live_grep, {})
vim.keymap.set('n', '<leader>b', builtin.git_branches, {})
vim.keymap.set('n', '<leader>m', builtin.oldfiles, {})
-- # indent_blankline
require("ibl").setup { indent = { char = "|" } }