update lsp, keymaps, format and some other settings

This commit is contained in:
xesc 2025-02-23 19:36:05 +01:00
parent c8a9410ad7
commit 49c040e36e
25 changed files with 423 additions and 861 deletions

View file

@ -5,6 +5,7 @@ vim.api.nvim_buf_set_keymap(0, "i", "<F5>", "<esc> :exec 'w' <bar> :exec '!xelat
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", "<esc> :exec 'w' <bar> :exec '!xelatex %'<cr>", {}) vim.api.nvim_buf_set_keymap(0, "v", "<F5>", "<esc> :exec 'w' <bar> :exec '!xelatex %'<cr>", {})
-- Open PDF-Viewer from LaTeX-file -- Open PDF-Viewer from LaTeX-file
vim.api.nvim_buf_set_keymap(0, "n", "cz", ":silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F6>", ":silent !zathura --fork %:r.pdf& <cr>", {}) vim.api.nvim_buf_set_keymap(0, "n", "<F6>", ":silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {}) vim.api.nvim_buf_set_keymap(0, "i", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {}) vim.api.nvim_buf_set_keymap(0, "v", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})

View file

@ -24,6 +24,7 @@ require("lazy").setup({
install = { install = {
colorscheme = { "everforest" } colorscheme = { "everforest" }
}, },
change_detection = { notify = false }
}) })

View file

@ -6,3 +6,15 @@ vim.api.nvim_create_autocmd("Filetype", {
pattern = "*", pattern = "*",
command = "setlocal formatoptions-=c formatoptions-=r formatoptions-=o" command = "setlocal formatoptions-=c formatoptions-=r formatoptions-=o"
}) })
-- persistent folds
vim.api.nvim_create_autocmd({"BufWinLeave"}, {
pattern = {"*.*"},
desc = "save view (folds), when closing file",
command = "mkview",
})
vim.api.nvim_create_autocmd({"BufWinEnter"}, {
pattern = {"*.*"},
desc = "load view (folds), when opening file",
command = "silent! loadview"
})

View file

@ -19,8 +19,16 @@ vim.api.nvim_set_keymap("n", "<C-l>", "<C-w>l", {})
-- buffer operations -- buffer operations
vim.api.nvim_set_keymap("n", "<leader><tab>", "<C-^>", {}) vim.api.nvim_set_keymap("n", "<leader><tab>", "<C-^>", {})
vim.api.nvim_set_keymap("n", "<leader>bd", "<cmd>bd<cr>", {}) vim.api.nvim_set_keymap("n", "<leader>bd", "<cmd>bd<cr>", {})
vim.api.nvim_set_keymap("n", "<S-h>", "<cmd>bprevious<cr>", {})
vim.api.nvim_set_keymap("n", "<S-l>", "<cmd>bnext<cr>", {}) -- quickfix and locationlist
vim.api.nvim_set_keymap("n", "<S-h>", "<cmd>cnext<cr>zz", {})
vim.api.nvim_set_keymap("n", "<S-l>", "<cmd>cprev<cr>zz", {})
vim.api.nvim_set_keymap("n", "<leader>h", "<cmd>lnext<cr>zz", {})
vim.api.nvim_set_keymap("n", "<leader>l", "<cmd>lprev<cr>zz", {})
vim.api.nvim_set_keymap("n", "<leader>L", "<cmd>lcl<cr>", {})
vim.api.nvim_set_keymap("n", "<leader>Q", "<cmd>cw<cr>", {})
vim.api.nvim_set_keymap("n", "<leader>q", "<cmd>ccl<cr>", {})
-- moving visual blocks -- moving visual blocks
vim.api.nvim_set_keymap("v", "J", ":m '>+1<cr>gv=gv", {}) vim.api.nvim_set_keymap("v", "J", ":m '>+1<cr>gv=gv", {})

View file

@ -16,14 +16,20 @@ vim.opt.completeopt = 'menu,menuone,noselect'
vim.opt.list = true vim.opt.list = true
-- correct tabbing -- correct tabbing
vim.opt.tabstop = 2 vim.opt.tabstop = 4
vim.opt.softtabstop = 2 vim.opt.softtabstop = 4
vim.opt.shiftwidth = 2 vim.opt.shiftwidth = 4
vim.opt.expandtab = true vim.opt.expandtab = true
-- enable foldcolumn -- enable foldcolumn
vim.wo.foldcolumn = "2" vim.wo.foldcolumn = "2"
-- disable wrap
vim.opt.wrap = false
-- allow "@" in filenames
vim.opt.isfname:append("@-@")
-- smart indenting by vim -- smart indenting by vim
vim.api.nvim_set_option("smartindent",true) vim.api.nvim_set_option("smartindent",true)
@ -39,7 +45,7 @@ vim.api.nvim_set_option("background", "dark")
-- always center -- always center
-- vim.api.nvim_set_option("scrolloff",999) -- vim.api.nvim_set_option("scrolloff",999)
vim.api.nvim_set_option("scrolloff",15) vim.opt.scrolloff = 10
-- spellchecking -- spellchecking
vim.wo.spell = true vim.wo.spell = true

View file

@ -32,7 +32,6 @@ return {
-- Actions -- Actions
map('n', '<leader>gB', function() gs.blame_line { full = true } end) map('n', '<leader>gB', function() gs.blame_line { full = true } end)
map('n', '<leader>gb', gs.toggle_current_line_blame) map('n', '<leader>gb', gs.toggle_current_line_blame)
end end
}) })
end, end,

View file

@ -26,10 +26,6 @@ return {
vim.keymap.set("n", "<leader>7", function() harpoon:list():select(7) end) vim.keymap.set("n", "<leader>7", function() harpoon:list():select(7) end)
vim.keymap.set("n", "<leader>8", function() harpoon:list():select(8) end) vim.keymap.set("n", "<leader>8", function() harpoon:list():select(8) end)
vim.keymap.set("n", "<leader>9", function() harpoon:list():select(9) end) vim.keymap.set("n", "<leader>9", function() harpoon:list():select(9) end)
-- Toggle previous & next buffers stored within Harpoon list
vim.keymap.set("n", "<C-P>", function() harpoon:list():prev() end)
vim.keymap.set("n", "<C-N>", function() harpoon:list():next() end)
end end
} }
} }

View file

@ -1,223 +0,0 @@
return {
{
"neovim/nvim-lspconfig",
-- event = "BufReadPre",
config = function()
require('lspconfig.ui.windows').default_options.border = 'rounded'
vim.api.nvim_set_hl(0, "LspInfoBorder", { bg = none, fg = "#9da9a0" })
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>cd', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<space>cl', "<cmd>LspInfo<cr>", opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
-- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
local on_attach = function(client, bufnr)
-- enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
end
local border = {
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
}
vim.diagnostic.config({
signs = { text = { [vim.diagnostic.severity.ERROR] = "", [vim.diagnostic.severity.WARN] = "", [vim.diagnostic.severity.HINT] = "", [vim.diagnostic.severity.INFO] = "" } },
float = { border = border },
virtual_text = {
prefix = '', -- Could be '●', '■', 'x', '▎', or anything else
},
update_in_insert = true,
})
-- LSP settings (for overriding per client)
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signatureHelp, { border = border })
end,
},
-- pretty ui
{
'nvimdev/lspsaga.nvim',
event = 'LspAttach',
config = function()
require('lspsaga').setup({
symbol_in_winbar = {
enable = false,
show_file = false
},
finder = {
keys = {
toggle_or_open = "<cr>",
quit = { '<Esc>', 'q' }
}
},
outline = {
win_position = 'right',
win_width = 32,
auto_preview = true,
},
lightbulb = {
enable = false
},
ui = {
code_action = '',
title = true,
border = 'rounded',
},
rename = {
in_select = false,
keys = {
quit = { '<Esc>', 'q' },
select = '<Space>'
}
},
hover_doc = {
open_cmd = '!firefox'
},
code_action = {
keys = {
quit = { '<Esc>', 'q' }
},
extend_gitsigns = false,
},
definition = {
keys = {
quit = { '<Esc>', 'q' },
},
},
diagnostic = {
border_follow = true,
extend_relatedInformation = true,
keys = {
quit = { '<Esc>', 'q' },
quit_in_show = { '<Esc>', 'q' },
}
}
})
vim.keymap.set('n', '<C-n>', "<cmd>Lspsaga term_toggle<cr>", opts)
vim.keymap.set('t', '<C-n>', "<cmd>Lspsaga term_toggle<cr>", opts)
vim.keymap.set('n', '<space>so', '<cmd>Lspsaga outline<cr>', opts)
vim.keymap.set('n', '<space>sf', '<cmd>Lspsaga finder<cr>', opts)
vim.keymap.set('n', '<space>sci', '<cmd>Lspsaga incoming_calls<cr>', opts)
vim.keymap.set('n', '<space>sco', '<cmd>Lspsaga outgoing_calls<cr>', opts)
vim.keymap.set('n', '<leader>k', '<cmd>Lspsaga hover_doc<cr>', bufopts)
vim.keymap.set('n', 'K', '<cmd>Lspsaga hover_doc<cr>', bufopts)
vim.keymap.set('n', '<space>ca', '<cmd>Lspsaga code_action<cr>', bufopts)
vim.keymap.set('n', '<space>sd', '<cmd>Lspsaga peek_definition<cr>', bufopts)
vim.keymap.set('n', '<space>st', '<cmd>Lspsaga peek_type_definition<cr>', bufopts)
vim.keymap.set('n', '<space>cw', "<cmd>Lspsaga rename mode=n<cr>", bufopts)
vim.keymap.set('n', '<space>ca', '<cmd>Lspsaga code_action<cr>', bufopts)
vim.keymap.set('n', '[e', '<cmd>Lspsaga diagnostic_jump_next<cr>', bufopts)
vim.keymap.set('n', ']e', '<cmd>Lspsaga diagnostic_jump_prev<cr>', bufopts)
end,
depedencies = {
'nvim-treesitter/nvim-treesitter',
'nvim-tree/nvim-web-devicons'
},
},
{
"williamboman/mason.nvim",
lazy = true,
cmd = "Mason",
config = function()
require("mason").setup({
PATH = "append",
ui = {
border = "rounded",
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = ""
}
}
})
end,
},
{
"williamboman/mason-lspconfig.nvim",
-- event = "BufReadPre",
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"clangd",
"rust_analyzer",
}
})
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 {
on_attach = on_attach,
handlers = handlers,
}
end,
}
end,
},
{
"nvimtools/none-ls.nvim",
-- event = "BufReadPost",
dependencies = {
{
"nvim-telescope/telescope-ui-select.nvim",
lazy = true,
config = function()
-- This is your opts table
require("telescope").setup {
extensions = {
["ui-select"] = {
-- require("telescope.themes").get_dropdown {
-- -- even more opts
-- }
}
}
}
require("telescope").load_extension("ui-select")
end,
},
},
opts = function()
local null_ls = require('null-ls')
return {
border = 'rounded',
on_attach = function(client, bufnr)
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', '<leader>K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<space>gt', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>cA', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', '<space>gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>cf', function() vim.lsp.buf.format { async = true } end, bufopts)
vim.keymap.set('v', '<space>cf', function() vim.lsp.buf.format { async = true } end, bufopts)
end,
sources = {
null_ls.builtins.diagnostics.trail_space.with {
disabled_filetypes = { "lua" }
},
null_ls.builtins.code_actions.gitsigns,
null_ls.builtins.diagnostics.yamllint,
null_ls.builtins.formatting.yamlfmt,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.shellharden,
},
}
end,
}
}

View file

@ -5,7 +5,7 @@ return {
opts = {}, opts = {},
config = function() config = function()
require 'marks'.setup({ require 'marks'.setup({
sign_priority = 5; sign_priority = 5,
}) })
end, end,
} }

View file

@ -1,196 +0,0 @@
return {
-- snippets
{
"L3MON4D3/LuaSnip",
lazy = true,
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
vim.api.nvim_set_hl(0, "PmenuSel", { fg = 'NONE', bg = '#272e33' })
vim.api.nvim_set_hl(0, "Pmenu", { fg = 'NONE', bg = '#1e2326' })
vim.api.nvim_set_hl(0, "CmpItemMenu", { fg = 'NONE', bg = '#272e33' })
vim.api.nvim_set_hl(0, "CmpItemMenuDefault", { fg = 'NONE', bg = '#272e33' })
vim.api.nvim_set_hl(0, "CmpItemKindFunction", { fg = '#d699b6', bg = 'NONE', italic = true })
vim.api.nvim_set_hl(0, "CmpItemKindSnippet", { fg = '#dbbc7f', bg = 'NONE', italic = true })
vim.api.nvim_set_hl(0, "CmpItemKindText", { fg = '#9da9a0', bg = 'NONE', italic = true })
vim.api.nvim_set_hl(0, "CmpItemKindVariable", { fg = '#7fbbb3', bg = 'NONE', italic = true })
end,
},
},
-- completion
{
"hrsh7th/nvim-cmp",
version = false,
event = {
-- "InsertEnter",
-- "CmdlineEnter",
"BufWinEnter",
},
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"saadparwaiz1/cmp_luasnip",
},
opts = function()
-- Set up nvim-cmp with luasnip
local kind_icons = {
Text = "",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "󰇽",
Variable = "󰂡",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
Operator = "󰆕",
TypeParameter = "󰅲"
}
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
local cmp = require("cmp")
return {
formatting = {
format = function(entry, vim_item)
-- Kind icons
vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
-- Source
vim_item.menu = ({
-- buffer = "[Buffer]",
-- nvim_lsp = "[LSP]",
-- luasnip = "[LuaSnip]",
-- nvim_lua = "[Lua]",
-- latex_symbols = "[LaTeX]",
buffer = "",
nvim_lsp = "",
luasnip = "",
nvim_lua = "",
latex_symbols = "",
})[entry.source.name]
return vim_item
end
},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
-- completion = {
-- autocomplete = false,
-- },
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
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(),
['<C-e>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.abort()
else
cmp.complete()
end
end),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
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 = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
{ name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
{
name = 'buffer',
option = {
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
},
},
}, {
}),
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
}),
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
}),
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
}),
}
end,
}
}

View file

@ -1,41 +0,0 @@
return {
{
"folke/trouble.nvim",
opts = {}, -- for default options, refer to the configuration section for custom setup.
cmd = "Trouble",
keys = {
{
"<leader>xx",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>xX",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>xs",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>xl",
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
desc = "LSP Definitions / references / ... (Trouble)",
},
{
"<leader>xL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>xQ",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
}
}

View file

@ -11,4 +11,3 @@ return {
end end
} }
} }

View file

@ -4,7 +4,7 @@ return {
opts = { opts = {
window = { window = {
backdrop = 1, backdrop = 1,
width = 101, width = 120,
}, },
plugins = { plugins = {
options = { options = {