-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
138 lines (124 loc) · 4.08 KB
/
init.lua
File metadata and controls
138 lines (124 loc) · 4.08 KB
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
require("nathaniel")
require("nathaniel.set")
-- Fold markers
vim.o.foldmethod = "marker"
-- Enable filetype detection
vim.g.maplocalleader = ","
vim.cmd("filetype on")
-- Install Lazy if it hasn't been installed yet
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.opt.rtp:append("~/.config/nvim/lua")
require("lazy").setup("plugins")
-- Source all Lua files in the after/plugin directory
local plugin_files = vim.fn.globpath("~/.config/nvim/lua/after/plugin", "*.lua", true, true)
for _, file in ipairs(plugin_files) do
dofile(file)
end
-- LSP setup
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("user_lsp_attach", { clear = true }),
callback = function(event)
local opts = { buffer = event.buf }
vim.keymap.set("n", "gd", function()
vim.lsp.buf.definition()
end, opts)
vim.keymap.set("n", "K", function()
vim.lsp.buf.hover()
end, opts)
vim.keymap.set("n", "<leader>vws", function()
vim.lsp.buf.workspace_symbol()
end, opts)
vim.keymap.set("n", "<leader>vd", function()
vim.diagnostic.open_float()
end, opts)
vim.keymap.set("n", "[d", function()
vim.diagnostic.goto_next()
end, opts)
vim.keymap.set("n", "]d", function()
vim.diagnostic.goto_prev()
end, opts)
vim.keymap.set("n", "<leader>vca", function()
vim.lsp.buf.code_action()
end, opts)
vim.keymap.set("n", "<leader>vrr", function()
vim.lsp.buf.references()
end, opts)
vim.keymap.set("n", "<leader>vrn", function()
vim.lsp.buf.rename()
end, opts)
vim.keymap.set("i", "<C-h>", function()
vim.lsp.buf.signature_help()
end, opts)
end,
})
local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()
require("mason").setup({})
require("mason-lspconfig").setup({
-- ensure_installed = {'rust_analyzer'},
handlers = {
function(server_name)
require("lspconfig")[server_name].setup({
capabilities = lsp_capabilities,
})
end,
lua_ls = function()
require("lspconfig").lua_ls.setup({
capabilities = lsp_capabilities,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
library = {
vim.env.VIMRUNTIME,
},
},
},
},
})
end,
},
})
local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }
-- this is the function that loads the extra snippets to luasnip
-- from rafamadriz/friendly-snippets
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
sources = {
{ name = "path" },
{ name = "nvim_lsp" },
{ name = "luasnip", keyword_length = 2 },
{ name = "buffer", keyword_length = 3 },
},
mapping = cmp.mapping.preset.insert({
["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
}),
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
})
-- Spellfile
vim.opt.spellfile = vim.fn.expand('~/.config/nvim/en.utf-8.add')
local vimrc = vim.fn.stdpath("config") .. "/vimrc.vim"
vim.cmd.source(vimrc)