2023-02-16 18:03:55 +01:00
|
|
|
vim.g.mapleader = " "
|
|
|
|
vim.g.maplocalleader = ","
|
|
|
|
|
|
|
|
-- FIX to create spell dir if not existent
|
|
|
|
local spelldir = vim.fn.stdpath("data") .. "/site/spell"
|
|
|
|
if not vim.loop.fs_stat(spelldir) then
|
2023-02-17 22:09:13 +01:00
|
|
|
vim.fn.mkdir(spelldir, "p")
|
2023-02-16 18:03:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
vim.opt.autoindent = true
|
2023-03-04 13:22:48 +01:00
|
|
|
vim.opt.backupdir = { vim.fn.stdpath("state") .. "/nvim/backup/" } -- don't store backup in files dir
|
2023-02-16 18:03:55 +01:00
|
|
|
vim.opt.clipboard = "unnamedplus" -- sync with system clipboard
|
|
|
|
vim.opt.conceallevel = 2
|
|
|
|
vim.opt.expandtab = true -- spaces instead of tabs
|
|
|
|
vim.opt.ignorecase = true
|
|
|
|
vim.opt.mouse = "a" -- mouse for all modes
|
|
|
|
vim.opt.number = true
|
|
|
|
vim.opt.relativenumber = true
|
|
|
|
vim.opt.scrolloff = 4 -- lines of context
|
|
|
|
vim.opt.shiftround = true -- round indent
|
|
|
|
vim.opt.shiftwidth = 0 -- use tabstop value
|
|
|
|
vim.opt.shortmess:append({ c = true })
|
|
|
|
vim.opt.signcolumn = "yes"
|
|
|
|
vim.opt.smartcase = true
|
|
|
|
vim.opt.splitbelow = true
|
|
|
|
vim.opt.splitright = true
|
|
|
|
vim.opt.tabstop = 2
|
|
|
|
vim.opt.termguicolors = true
|
|
|
|
vim.opt.undofile = true
|
|
|
|
vim.opt.undolevels = 10000
|
|
|
|
vim.opt.updatetime = 300
|
|
|
|
vim.opt_local.spell = true
|
|
|
|
vim.opt_local.spelllang = { "en", "de_20" } -- all English regions and new German spelling
|
|
|
|
|
2023-03-02 09:13:46 +01:00
|
|
|
if vim.g.neovide then
|
|
|
|
vim.opt.guifont = "Fira Code Nerd Font:h10"
|
|
|
|
vim.g.neovide_scale_factor = 0.7
|
|
|
|
end
|
|
|
|
|
2023-03-09 16:17:27 +01:00
|
|
|
require("impatient")
|
|
|
|
|
2023-02-16 18:03:55 +01:00
|
|
|
local wk = require("which-key")
|
|
|
|
|
|
|
|
require("nvim-treesitter.configs").setup({
|
2023-02-17 22:09:13 +01:00
|
|
|
sync_install = false,
|
|
|
|
auto_install = false,
|
|
|
|
highlight = {
|
|
|
|
enable = true,
|
2023-03-04 13:22:48 +01:00
|
|
|
additional_vim_regex_highlighting = false,
|
2023-02-17 22:09:13 +01:00
|
|
|
},
|
2023-02-16 18:03:55 +01:00
|
|
|
})
|
2023-02-17 12:38:44 +01:00
|
|
|
|
|
|
|
local cmp = require("cmp")
|
|
|
|
local luasnip = require("luasnip")
|
2023-03-04 13:22:48 +01:00
|
|
|
require("copilot_cmp").setup()
|
|
|
|
|
2023-02-17 12:38:44 +01:00
|
|
|
cmp.setup({
|
2023-02-18 16:22:21 +01:00
|
|
|
formatting = {
|
2023-03-04 13:22:48 +01:00
|
|
|
format = require("lspkind").cmp_format({
|
2023-02-18 16:22:21 +01:00
|
|
|
mode = "symbol", -- show only symbol annotations
|
2023-02-23 13:34:59 +01:00
|
|
|
maxwidth = 50, -- prevent the popup from showing more than provided characters
|
|
|
|
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
|
2023-02-19 13:24:22 +01:00
|
|
|
symbol_map = {
|
|
|
|
Copilot = "",
|
|
|
|
},
|
2023-02-18 16:22:21 +01:00
|
|
|
}),
|
|
|
|
},
|
2023-02-17 22:09:13 +01:00
|
|
|
snippet = {
|
|
|
|
-- REQUIRED - you must specify a snippet engine
|
|
|
|
expand = function(args)
|
|
|
|
require("luasnip").lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<C-e>"] = cmp.mapping.abort(),
|
2023-02-23 13:34:59 +01:00
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
2023-02-17 22:09:13 +01:00
|
|
|
["<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 = {
|
2023-02-18 16:23:58 +01:00
|
|
|
{ name = "buffer", priority = 1 },
|
|
|
|
{ name = "copilot", priority = 8 },
|
|
|
|
{ name = "luasnip", priority = 7 },
|
|
|
|
{ name = "nvim_lsp", priority = 9 },
|
2023-02-18 16:24:38 +01:00
|
|
|
{ name = "orgmode", priority = 9 },
|
2023-02-17 22:09:13 +01:00
|
|
|
},
|
2023-02-17 12:38:44 +01:00
|
|
|
})
|
|
|
|
|
2023-02-17 22:09:13 +01:00
|
|
|
---merge tables
|
|
|
|
---@param ... table[]
|
|
|
|
---@return table
|
|
|
|
local function table_merge(...)
|
|
|
|
local tables_to_merge = { ... }
|
|
|
|
assert(#tables_to_merge > 1, "There should be at least two tables to merge them")
|
|
|
|
|
|
|
|
for k, t in ipairs(tables_to_merge) do
|
|
|
|
assert(type(t) == "table", string.format("Expected a table as function parameter %d", k))
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = tables_to_merge[1]
|
|
|
|
|
|
|
|
for i = 2, #tables_to_merge do
|
|
|
|
local from = tables_to_merge[i]
|
|
|
|
for k, v in pairs(from) do
|
|
|
|
if type(v) == "table" then
|
|
|
|
result[k] = result[k] or {}
|
|
|
|
result[k] = table_merge(result[k], v)
|
|
|
|
else
|
|
|
|
result[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2023-02-18 16:25:09 +01:00
|
|
|
local lsp_lines = require("lsp_lines")
|
|
|
|
lsp_lines.setup()
|
|
|
|
-- Disable virtual_text since it's redundant due to lsp_lines.
|
|
|
|
vim.diagnostic.config({
|
|
|
|
virtual_text = false,
|
|
|
|
})
|
|
|
|
|
2023-02-18 13:35:11 +01:00
|
|
|
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
|
2023-03-04 13:22:48 +01:00
|
|
|
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
|
2023-03-05 14:02:54 +01:00
|
|
|
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
|
|
|
|
vim.o.statuscolumn = "%= "
|
|
|
|
-- FIXME: figure out how to put on the other side without having to do a lot of shifting
|
|
|
|
.. "%s" -- sign column
|
|
|
|
.. "%{%" -- evaluate this, and then evaluate what it returns
|
|
|
|
.. "&number ?"
|
|
|
|
.. "(v:relnum ?"
|
|
|
|
-- when showing relative numbers, make sure to pad so things don't shift as you move the cursor
|
|
|
|
.. 'printf("%"..len(line("$")).."s", v:relnum)'
|
|
|
|
.. ":"
|
|
|
|
.. "v:lnum"
|
|
|
|
.. ")"
|
|
|
|
.. ":"
|
|
|
|
.. '""'
|
|
|
|
.. " " -- space between lines and fold
|
|
|
|
.. "%}"
|
|
|
|
.. "%= "
|
|
|
|
.. "%#FoldColumn#" -- highlight group for fold
|
|
|
|
.. "%{" -- expression for showing fold expand/colapse
|
|
|
|
.. "foldlevel(v:lnum) > foldlevel(v:lnum - 1)" -- any folds?
|
|
|
|
.. "? (foldclosed(v:lnum) == -1" -- currently open?
|
|
|
|
.. '? ""' -- point down
|
|
|
|
.. ': ""' -- point to right
|
|
|
|
.. ")"
|
|
|
|
.. ': " "' -- blank for no fold, or inside fold
|
|
|
|
.. "}"
|
|
|
|
.. "%= " -- spacing between end of column and start of text
|
|
|
|
|
2023-03-04 13:22:48 +01:00
|
|
|
-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself
|
|
|
|
wk.register({
|
|
|
|
z = {
|
|
|
|
R = { require("ufo").openAllFolds, "Open all folds" },
|
|
|
|
M = { require("ufo").closeAllFolds, "Close all folds" },
|
|
|
|
},
|
|
|
|
})
|
|
|
|
-- Tell the server the capability of foldingRange,
|
|
|
|
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
|
|
|
|
capabilities.textDocument.foldingRange = {
|
|
|
|
dynamicRegistration = false,
|
|
|
|
lineFoldingOnly = true,
|
|
|
|
}
|
|
|
|
require("ufo").setup()
|
|
|
|
|
2023-02-27 23:48:21 +01:00
|
|
|
require("lspsaga").setup({
|
|
|
|
symbol_in_winbar = {
|
|
|
|
enable = false,
|
|
|
|
},
|
2023-03-05 14:04:00 +01:00
|
|
|
lightbulb = {
|
|
|
|
enable = true,
|
|
|
|
enable_in_insert = true,
|
|
|
|
sign = true,
|
|
|
|
sign_priority = 40,
|
|
|
|
virtual_text = false,
|
|
|
|
},
|
2023-02-27 23:48:21 +01:00
|
|
|
})
|
|
|
|
|
2023-02-18 13:35:11 +01:00
|
|
|
local lspconfig = require("lspconfig")
|
2023-02-18 16:25:09 +01:00
|
|
|
local on_attach_def = function(_, bufnr)
|
|
|
|
wk.register({
|
2023-02-27 23:48:21 +01:00
|
|
|
K = { "<cmd>Lspsaga hover_doc ++quiet<cr>", "show info" },
|
2023-02-18 16:25:09 +01:00
|
|
|
["<leader>"] = {
|
|
|
|
l = {
|
|
|
|
name = "lsp",
|
2023-02-27 23:48:21 +01:00
|
|
|
d = { "<cmd>Lspsaga show_cursor_diagnostics<cr>", "open diagnostic window" },
|
|
|
|
n = { "<cmd>Lspsaga diagnostic_jump_next<CR>", "next error" },
|
|
|
|
p = { "<cmd>Lspsaga diagnostic_jump_prev<CR>", "prev error" },
|
|
|
|
c = { "<cmd>Lspsaga code_action<cr>", "code action" },
|
|
|
|
r = { "<cmd>Lspsaga rename<cr>", "rename" },
|
2023-02-27 23:53:35 +01:00
|
|
|
i = { "<cmd>Lspsaga hover_doc ++keep<cr>", "show info (sticky)" },
|
2023-02-18 16:25:09 +01:00
|
|
|
f = {
|
2023-02-18 13:35:11 +01:00
|
|
|
function()
|
|
|
|
vim.lsp.buf.format({ async = true })
|
|
|
|
end,
|
|
|
|
"format (lsp)",
|
2023-02-18 16:25:09 +01:00
|
|
|
mode = { "n", "v" },
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
2023-02-18 16:25:09 +01:00
|
|
|
},
|
|
|
|
w = {
|
|
|
|
name = "workspace",
|
|
|
|
a = { vim.lsp.buf.add_workspace_folder, "add workspace folder" },
|
|
|
|
r = { vim.lsp.buf.remove_workspace_folder, "remove workspace folder" },
|
|
|
|
l = {
|
|
|
|
function()
|
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end,
|
|
|
|
"list workspace folders",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t = {
|
|
|
|
name = "toggle",
|
|
|
|
l = { lsp_lines.toggle, "lsp lines" },
|
|
|
|
},
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
|
|
|
g = {
|
|
|
|
name = "goto",
|
2023-02-27 23:48:21 +01:00
|
|
|
d = { "<cmd>Lspsaga peek_definition<cr>", "definition" },
|
|
|
|
t = { "<cmd>Lspsaga peek_type_definition<cr>", "type defininition" },
|
2023-02-27 23:53:35 +01:00
|
|
|
h = { "<cmd>Lspsaga lsp_finder<CR>", "lsp finder" },
|
2023-02-18 13:35:11 +01:00
|
|
|
},
|
2023-02-18 17:55:20 +01:00
|
|
|
}, { buffer = bufnr, silent = true })
|
2023-02-18 13:35:11 +01:00
|
|
|
end
|
|
|
|
|
2023-02-17 22:09:13 +01:00
|
|
|
local lspconfig_default_options = {
|
|
|
|
on_attach = on_attach_def,
|
|
|
|
capabilities = capabilities,
|
|
|
|
flags = {
|
|
|
|
debounce_text_changes = 100,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
---function to add default options to lspconfig
|
|
|
|
---@param lsp string
|
|
|
|
---@param options table
|
|
|
|
---@return nil
|
|
|
|
local function lspconfig_setup(lsp, options)
|
|
|
|
local final_options = table_merge(lspconfig_default_options, options)
|
|
|
|
lspconfig[lsp].setup(final_options)
|
2023-02-17 12:38:44 +01:00
|
|
|
end
|
|
|
|
|
2023-02-27 23:04:23 +01:00
|
|
|
local servers = { "nil_ls", "pylsp", "rust_analyzer", "ruff_lsp" }
|
2023-02-17 12:38:44 +01:00
|
|
|
for _, lsp in ipairs(servers) do
|
2023-02-17 22:09:13 +01:00
|
|
|
lspconfig_setup(lsp, {})
|
2023-02-17 12:38:44 +01:00
|
|
|
end
|
|
|
|
|
2023-02-17 22:09:13 +01:00
|
|
|
lspconfig_setup("lua_ls", {
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = "LuaJIT",
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = { "vim" },
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
checkThirdParty = false,
|
|
|
|
},
|
|
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
format = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 12:38:44 +01:00
|
|
|
})
|