-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
453 lines (429 loc) · 15.8 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
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)
-- User options
vim.g.mapleader = " "
vim.o.relativenumber = true
vim.o.number = true
vim.o.undofile = true
vim.o.expandtab = true
vim.o.shiftwidth = 4
vim.o.completeopt = "menu,menuone,noselect"
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.o.termguicolors = true
vim.o.conceallevel = 2
vim.o.cmdheight = 0
vim.o.foldenable = true
vim.o.mouse = ""
local map = vim.keymap.set
map("n", "<Leader>so", ":so %<CR>")
map("n", "<Leader>h", ":wincmd h<CR>")
map("n", "<Leader>j", ":wincmd j<CR>")
map("n", "<Leader>k", ":wincmd k<CR>")
map("n", "<Leader>l", ":wincmd l<CR>")
map("n", "<Leader>fs", vim.lsp.buf.format)
map("n", "K", vim.lsp.buf.hover)
map("n", "<leader>r", vim.lsp.buf.rename)
map("n", "<C-n>", vim.diagnostic.goto_next)
map("n", "<C-b>", vim.diagnostic.goto_prev)
-- map("i", "<Tab>", function() if vim.snippet.active() then vim.snippet.expand() end end)
map('i', '<C-Space>', '<C-x><C-o>') -- Force Trigger completion
map('i', '<C-j>', [[pumvisible() ? "\<C-n>" : "\<C-j>"]], { expr = true })
map('i', '<C-k>', [[pumvisible() ? "\<C-p>" : "\<C-k>"]], { expr = true })
map({ "n", "v" }, "≠", "<C-d>zz")
map({ "n", "v" }, "÷", "<C-u>zz")
map({ "n", "v" }, "<C-j>", "<C-d>zz")
map({ "n", "v" }, "<C-k>", "<C-u>zz")
map("t", "<Esc>", "<C-\\><C-n>")
-- export NVIM_WORK=1 at work and it will apply custom keybinds
local at_work = vim.env.NVIM_WORK and true
if at_work then
map("n", "<Leader>=", "<C-^>")
end
require("lazy").setup({
{
"stevearc/oil.nvim",
config = function()
require("oil").setup({
view_options = {
show_hidden = true,
},
natural_order = true,
})
vim.keymap.set("n", at_work and "=" or "-", "<CMD>Oil --float<CR>", { desc = "Open parent directory" })
end
},
{
"danymat/neogen",
dev = true,
config = function()
require("neogen").setup({
--snippet_engine = "luasnip",
languages = {
python = { template = { annotation_convention = "reST" } },
}
})
vim.keymap.set("n", "<Leader>nf", ":Neogen func<CR>")
vim.keymap.set("n", "<Leader>nc", ":Neogen class<CR>")
end
},
{
"nvim-neorg/neorg",
dev = true
},
{
"numToStr/Comment.nvim",
config = function()
require("Comment").setup({
toggler = {
line = "<Leader>cc",
block = "<Leader>bc",
},
opleader = {
line = "<Leader>c",
block = "<Leader>b",
},
extra = {
eol = "<Leader>ca",
},
})
end
},
{
"ThePrimeagen/harpoon",
config = function()
vim.keymap.set("n", "<Leader>a", function() require("harpoon.mark").add_file() end)
vim.keymap.set("n", "<Leader>o", function() require("harpoon.ui").toggle_quick_menu() end)
vim.keymap.set("n", "<Leader>&", function() require("harpoon.ui").nav_file(1) end)
vim.keymap.set("n", "<Leader>é", function() require("harpoon.ui").nav_file(2) end)
vim.keymap.set("n", "<Leader>\"", function() require("harpoon.ui").nav_file(3) end)
vim.keymap.set("n", "<Leader>'", function() require("harpoon.ui").nav_file(4) end)
end
},
{
"ggandor/leap.nvim",
config = function()
require('leap').add_default_mappings()
end
},
{
"nvim-lualine/lualine.nvim",
config = function()
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'auto',
},
}
end
},
{
"ray-x/lsp_signature.nvim",
event = "InsertEnter",
opts = {
bind = true,
handler_opts = {
border = "rounded"
}
},
config = function(_, opts) require 'lsp_signature'.setup(opts) end
},
{
"neovim/nvim-lspconfig",
config = function()
require("mason").setup()
require("mason-lspconfig").setup()
require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {}
end,
["lua_ls"] = function()
require("lspconfig").lua_ls.setup {
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
},
}
},
}
end
})
local cmp = require("cmp")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
require('luasnip.loaders.from_vscode').lazy_load()
local cmp_config = {
experimental = {
ghost_text = true
},
preselect = 'item',
completion = {
completeopt = 'menu,menuone,noinsert'
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
["<Tab>"] = cmp.mapping.confirm({
-- this is the important line
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<C-l>"] = cmp.mapping(function(fallback)
if luasnip and luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<C-h>"] = cmp.mapping(function(fallback)
if luasnip and luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" }, -- For luasnip users.
}, {
{ name = "buffer" },
}),
formatting = {
fields = {
cmp.ItemField.Kind,
cmp.ItemField.Abbr,
cmp.ItemField.Menu,
},
format = lspkind.cmp_format({
mode = 'symbol',
maxwidth = 40,
ellipsis_char = '...',
symbol_map = { Copilot = "" }
}),
},
}
cmp.setup(cmp_config)
require("mason-null-ls").setup({ automatic_setup = true })
end,
dependencies = {
-- LSP Support
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
-- Autocompletion
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua",
-- Snippets
{ "L3MON4D3/LuaSnip", version = "v2.*", },
"rafamadriz/friendly-snippets",
--null-ls
-- TODO: check here, maybe null-ls is not to be used anymore
"jose-elias-alvarez/null-ls.nvim",
"jayp0521/mason-null-ls.nvim",
"onsails/lspkind.nvim",
"ray-x/lsp_signature.nvim",
{
'windwp/nvim-autopairs',
event = "InsertEnter",
config = true
-- use opts = {} for passing setup options
-- this is equivalent to setup({}) function
}
},
},
{ 'kylechui/nvim-surround', config = true },
{
"nvim-treesitter/nvim-treesitter",
config = function()
local configs = require("nvim-treesitter.configs")
configs.setup({
highlight = {
ensure_installed = { "c", "lua", "python", "vim", "vimdoc", "html" },
enable = true,
additional_vim_regex_highlighting = { "markdown" },
indent = { enable = true },
},
playground = {
enable = true,
}
})
end
},
{
"rose-pine/neovim",
name = "rose-pine",
config = function()
require("rose-pine").setup({
dark_variant = "moon",
disable_background = true,
--extend_background_behind_borders = true,
styles = { transparency = true },
})
vim.cmd("colorscheme rose-pine-moon")
end
},
{
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local telescope = require("telescope")
telescope.load_extension("workspaces")
telescope.setup({
extensions = {
workspaces = {
-- keep insert mode after selection in the picker, default is false
keep_insert = true,
},
},
})
vim.keymap.set("n", "<C-f>", ":Telescope find_files<CR>")
vim.keymap.set("n", "<Leader>ff", ":Telescope live_grep<CR>")
vim.keymap.set("n", "<Leader>fb", ":Telescope buffers<CR>")
vim.keymap.set("n", "<Leader>fh", ":Telescope help_tags<CR>")
vim.keymap.set("n", "<Leader>gr", ":Telescope lsp_references<CR>")
vim.keymap.set("n", "<Leader>gd", ":Telescope lsp_definitions<CR>")
vim.keymap.set("n", "<Leader>ds", ":Telescope lsp_document_symbols symbols=func,function,class<CR>")
vim.keymap.set("n", "<C-a>", ":lua vim.lsp.buf.code-action()<CR>")
vim.keymap.set("n", "<Leader>p", ":Telescope workspaces<CR>")
end
},
{
"natecraddock/workspaces.nvim",
config = function()
require("workspaces").setup({
hooks = {
open = { "Telescope find_files" },
}
})
end
},
-- {
-- "zk-org/zk-nvim",
-- enabled = false,
-- config = function()
-- local zk = require("zk")
-- local commands = require("zk.commands")
--
-- zk.setup({
-- picker = "telescope",
-- })
--
-- commands.add("ZkStart", function()
-- zk.edit({ matchStrategy = "re", match = { "§§" } }, { title = "Starting Points" })
-- end)
--
-- vim.keymap.set("n", "<Leader>za", "<CMD>:ZkStart<CR>", { desc = "Open Starting Point Notes" })
-- vim.keymap.set("n", "<Leader>zf", "<CMD>ZkNotes {sort = {'modified'}}<CR>", { desc = "Open Zk Notes" })
-- vim.keymap.set("n", "<Leader>zt", "<CMD>:ZkTags {sort= {'note-count'} }<CR>", { desc = "Open Zk Notes" })
-- vim.keymap.set("n", "<leader>zn",
-- "<Cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<CR>")
-- end
-- },
{
"epwalsh/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
-- ft = "markdown",
-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
-- event = {
-- -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
-- -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/*.md"
-- -- refer to `:h file-pattern` for more examples
-- "BufReadPre path/to/my-vault/*.md",
-- "BufNewFile path/to/my-vault/*.md",
-- },
dependencies = {
-- Required.
"nvim-lua/plenary.nvim",
-- see below for full list of optional dependencies 👇
},
config = function()
require("obsidian").setup {
workspaces = {
{
name = "personal",
path = "~/Developer/Brain",
},
},
daily_notes = {
folder = "Daily",
}
-- Optional, completion of wiki links, local markdown links, and tags using nvim-cmp.
}
vim.keymap.set("n", "<Leader>za", "<CMD>:ObsidianSearch §§<CR>", { desc = "Open Starting Point Notes" })
vim.keymap.set("n", "<Leader>zf", "<CMD>:ObsidianQuickSwitch<CR>", { desc = "Open Starting Point Notes" })
vim.keymap.set("n", "<Leader>zt", "<CMD>:ObsidianTags<CR>", { desc = "Open Starting Point Notes" })
-- TODO: here
-- vim.keymap.set("n", "<Leader>zf", "<CMD>ZkNotes {sort = {'modified'}}<CR>", { desc = "Open Zk Notes" })
-- vim.keymap.set("n", "<Leader>zt", "<CMD>:ZkTags {sort= {'note-count'} }<CR>", { desc = "Open Zk Notes" })
-- vim.keymap.set("n", "<leader>zn",
-- "<Cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<CR>")
-- end
end
},
{
"nvimtools/none-ls.nvim",
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.black,
},
})
end
},
"sindrets/diffview.nvim",
"nvim-treesitter/nvim-treesitter-context",
{
"folke/zen-mode.nvim",
config = function()
require("zen-mode").setup {
plugins = {
wezterm = {
enabled = true,
-- can be either an absolute font size or the number of incremental steps
font = "+4", -- (10% increase per step)
},
}
}
vim.keymap.set("n", "<Leader>zz", "<CMD>:ZenMode<CR>")
end
}
}, {
dev = {
path = "~/Developer/",
fallback = true
}
})