Nvim: More QoL improvements

This commit is contained in:
Tobias Manske 2023-01-26 02:07:56 +01:00
parent d933f8866a
commit 773a17a91a
Signed by: tobias
GPG Key ID: E83C743C1FC2F79A
3 changed files with 143 additions and 10 deletions

View File

@ -4,6 +4,7 @@
[nvim.files]
"nvim/init.lua" = { target = "~/.config/nvim/init.lua", type = "symbolic" }
"nvim/lua" = { target = "~/.config/nvim/lua", type = "symbolic" }
[git.files]
"git/.gitconfig" = { target = "~/.config/git/config", type = "symbolic" }

View File

@ -7,6 +7,9 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.cmd [[packadd packer.nvim]]
end
-- IMPORTS
local helpers = require('helpers')
require('packer').startup(function(use)
-- Package manager
use 'wbthomason/packer.nvim'
@ -18,6 +21,9 @@ require('packer').startup(function(use)
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'jose-elias-alvarez/null-ls.nvim',
'jay-babu/mason-null-ls.nvim',
-- Useful status updates for LSP
'j-hui/fidget.nvim',
@ -29,13 +35,13 @@ require('packer').startup(function(use)
use { -- Autocompletion
'hrsh7th/nvim-cmp',
requires = {
'onsails/lspkind.nvim',
'hrsh7th/cmp-nvim-lsp',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-buffer', -- Buffer completion
'hrsh7th/cmp-path', -- File path completion
'hrsh7th/cmp-nvim-lua', -- Lua completion
},
}
@ -65,6 +71,7 @@ require('packer').startup(function(use)
-- Fuzzy Finder (files, lsp, etc)
use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } }
use { 'nvim-telescope/telescope-ui-select.nvim' }
-- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 }
@ -88,18 +95,37 @@ require('packer').startup(function(use)
use {
"zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
event = "VimEnter",
config = function()
vim.schedule(function()
require("copilot").setup()
require("copilot").setup({
cmp = { enabled = true },
suggestion = { enabled = false },
panel = { enabled = false }
})
end)
end,
}
use {
"zbirenbaum/copilot-cmp",
after = { "copilot.lua" },
module = "copilot_cmp",
config = function()
require("copilot_cmp").setup()
end
}
use 'majutsushi/tagbar'
-- Parens
use 'jiangmiao/auto-pairs'
use {
"windwp/nvim-autopairs",
event = "InsertEnter",
config = function() require("nvim-autopairs").setup {} end
}
use 'tpope/vim-surround'
-- Todo comment highlight + diagnostics + navigation
@ -323,12 +349,26 @@ require('gitsigns').setup {
-- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()`
local action_layout = require("telescope.actions.layout")
require('telescope').setup {
defaults = {
mappings = {
n = {
["<M-p>"] = action_layout.toggle_preview
},
i = {
['<C-u>'] = false,
['<C-d>'] = false,
["<M-p>"] = action_layout.toggle_preview
},
},
},
extensions = {
["ui-select"] = {
layout_strategy = "cursor",
layout_config = {
width = { 0.8, max = 120 },
height = { 0.8, max = 20 },
},
},
},
@ -337,6 +377,8 @@ require('telescope').setup {
-- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf')
require("telescope").load_extension("ui-select")
-- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
@ -495,7 +537,6 @@ local on_attach = function(client, bufnr)
-- to define small helper and utility functions so you don't have to repeat yourself
if client.name == "ltex" then
print("loaded ltex extra")
require("ltex_extra").setup {
load_langs = { "de-DE", "en-US" }, -- table <string> : languages for witch dictionaries will be loaded
init_check = true, -- boolean : whether to load dictionaries on startup
@ -504,9 +545,8 @@ local on_attach = function(client, bufnr)
}
end
-- many times.
-- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
-- helpers.diagnostic_on_cursor_hold(bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
@ -560,6 +600,7 @@ local servers = {
pyright = {},
bashls = {},
ansiblels = {},
dockerls = {},
marksman = {},
rust_analyzer = {},
yamlls = {},
@ -591,6 +632,16 @@ local servers = {
},
}
local linters = {
shellcheck = {},
shfmt = {},
yamllint = {},
yamlfmt = {},
black = {},
hadolint = {}, -- Dockerfile
gitlint = {},
editorconfig_checker = {},
}
-- Setup neovim lua configuration
require('neodev').setup()
--
@ -603,6 +654,9 @@ require('mason').setup()
-- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig'
local mason_null_ls = require 'mason-null-ls'
local null_ls = require 'null-ls'
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
@ -618,12 +672,31 @@ mason_lspconfig.setup_handlers {
end,
}
mason_null_ls.setup {
ensure_installed = vim.tbl_keys(linters),
automatic_setup = true
}
null_ls.setup {
sources = {
null_ls.builtins.code_actions.gitsigns,
},
on_attach = on_attach,
}
mason_null_ls.setup_handlers()
-- Turn on lsp status information
require('fidget').setup()
-- nvim-cmp setup
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require 'lspkind'
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
cmp.setup {
snippet = {
@ -631,13 +704,17 @@ cmp.setup {
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
select = false, -- false: only accept if explicitly selected. Otherwise <CR> after <dot> becomes a pita
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
@ -658,13 +735,48 @@ cmp.setup {
end
end, { 'i', 's' }),
},
sorting = {
priority_weight = 2,
comparators = {
-- require("copilot_cmp.comparators").prioritize,
-- require("copilot_cmp.comparators").score,
--
-- Below is the default comparitor list and order for nvim-cmp
cmp.config.compare.offset,
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
cmp.config.compare.locality,
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
},
formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
symbol_map = {
Copilot = "",
},
-- The function below will be called before any actual modifications from lspkind
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
before = function(entry, vim_item)
return vim_item
end
})
},
sources = {
{ name = 'copilot' },
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lua' },
},
}

20
nvim/lua/helpers.lua Normal file
View File

@ -0,0 +1,20 @@
local helpers = {}
function helpers.diagnostic_on_cursor_hold(bufnr)
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end
})
end
return helpers