-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.lua
229 lines (206 loc) · 6.19 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
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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local plugins = {
{ 'AlexvZyl/nordic.nvim' },
{ 'neovim/nvim-lspconfig' },
--- make things a bit Luan's vim-ier
{ 'ctrlpvim/ctrlp.vim' },
{ 'kevinhwang91/promise-async' },
{ 'kevinhwang91/nvim-ufo' },
{
'nvim-treesitter/nvim-treesitter',
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "elixir", "eex", "heex" },
highlight = { enable = true },
indent = { enable = true },
})
end
},
{
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
end,
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
{ "williamboman/mason.nvim" },
{ "williamboman/mason-lspconfig.nvim" }
},
{
'nvim-telescope/telescope.nvim',
tag = '0.1.2',
dependencies = { 'nvim-lua/plenary.nvim' }
},
{
"hrsh7th/nvim-cmp",
version = false, -- last release is way too old
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
},
-- Not all LSP servers add brackets when completing a function.
-- To better deal with this, LazyVim adds a custom option to cmp,
-- that you can configure. For example:
--
-- ```lua
-- opts = {
-- auto_brackets = { "python" }
-- }
-- ```
opts = function()
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
local cmp = require("cmp")
local defaults = require("cmp.config.default")()
local auto_select = true
return {
auto_brackets = {}, -- configure any filetype to auto add brackets
completion = {
completeopt = "menu,menuone,noinsert" .. (auto_select and "" or ",noselect"),
},
preselect = auto_select and cmp.PreselectMode.Item or cmp.PreselectMode.None,
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
--["<CR>"] = LazyVim.cmp.confirm({ select = auto_select }),
--["<C-y>"] = LazyVim.cmp.confirm({ select = true }),
--["<S-CR>"] = LazyVim.cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<C-CR>"] = function(fallback)
cmp.abort()
fallback()
end,
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "path" },
}, {
{ name = "buffer" },
}),
formatting = {
format = function(entry, item)
--local icons = LazyVim.config.icons.kinds
--if icons[it:em.kind] then
-- item.kind = icons[item.kind] .. item.kind
--end
local widths = {
abbr = vim.g.cmp_widths and vim.g.cmp_widths.abbr or 40,
menu = vim.g.cmp_widths and vim.g.cmp_widths.menu or 30,
}
for key, width in pairs(widths) do
if item[key] and vim.fn.strdisplaywidth(item[key]) > width then
item[key] = vim.fn.strcharpart(item[key], 0, width - 1) ..
"…"
end
end
return item
end,
},
experimental = {
ghost_text = {
hl_group = "CmpGhostText",
},
},
sorting = defaults.sorting,
}
end
} }
require("lazy").setup(plugins)
vim.o.foldcolumn = '1' -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
require("mason").setup()
require("mason-lspconfig").setup()
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "rust_analyzer" },
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
--local language_servers = require("lspconfig").util.available_servers() -- or list servers manually like {'gopls', 'clangd'}
local language_servers = { 'lua_ls', 'gopls' }
for _, ls in ipairs(language_servers) do
require('lspconfig')[ls].setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = { globals = { 'vim' } }
}
}
-- you can add other fields for setting up lsp server in this table
})
end
require('ufo').setup()
-- Format on writes
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = vim.fn.bufnr(),
callback = function()
vim.lsp.buf.format({ timeout_ms = 3000 })
end,
})
vim.keymap.set('n', 'zR', require('ufo').openAllFolds)
vim.keymap.set('n', 'zM', require('ufo').closeAllFolds)
--- keybindings
local wk = require("which-key")
wk.register({
f = {
name = "file", -- optional group name
f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
g = { "<cmd>Telescope live_grep<cr>", "Full Text Search" },
b = { "<cmd>Telescope buffers<cr>", "Buffers" },
},
d = {
name = "diagnostic",
o = { "<cmd>lua vim.diagnostic.open_float()<cr>", "Open Diagnostic" },
n = { "<cmd>lua vim.diagnostic.goto_next()<cr>", "Next Diagnostic" },
p = { "<cmd>lua vim.diagnostic.goto_prev()<cr>", "Previous Diagnostic" },
d = { "<cmd>Telescope diagnostics<cr>", "List Diagnostics" }
}
}, { prefix = "<leader>" })
vim.api.nvim_create_autocmd({ "LspAttach" }, {
callback = function()
wk.register({
g = {
name = "Goto",
d = { vim.lsp.buf.definition, "Go to definition" },
r = { require("telescope.builtin").lsp_references,
"Open a telescope window with references" },
},
}, { buffer = 0 })
end
})
-- autosave
vim.opt.autowriteall = true
--- somehow, this stops Nvim from adding a tab
--- when it autoindents a line
--= in addition to the spaces its copying from the above line
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
--- set line numbers for pairing
vim.opt.number = true
--- enable syntax highlighting
vim.opt.syntax = "on"
--- enable 24-bit RGB colors
vim.opt.termguicolors = true
--- set the colorscheme
vim.cmd("colorscheme nordic")