Nvim: More QoL improvements
This commit is contained in:
parent
d933f8866a
commit
773a17a91a
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
[nvim.files]
|
[nvim.files]
|
||||||
"nvim/init.lua" = { target = "~/.config/nvim/init.lua", type = "symbolic" }
|
"nvim/init.lua" = { target = "~/.config/nvim/init.lua", type = "symbolic" }
|
||||||
|
"nvim/lua" = { target = "~/.config/nvim/lua", type = "symbolic" }
|
||||||
|
|
||||||
[git.files]
|
[git.files]
|
||||||
"git/.gitconfig" = { target = "~/.config/git/config", type = "symbolic" }
|
"git/.gitconfig" = { target = "~/.config/git/config", type = "symbolic" }
|
||||||
|
132
nvim/init.lua
132
nvim/init.lua
@ -7,6 +7,9 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
|||||||
vim.cmd [[packadd packer.nvim]]
|
vim.cmd [[packadd packer.nvim]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- IMPORTS
|
||||||
|
local helpers = require('helpers')
|
||||||
|
|
||||||
require('packer').startup(function(use)
|
require('packer').startup(function(use)
|
||||||
-- Package manager
|
-- Package manager
|
||||||
use 'wbthomason/packer.nvim'
|
use 'wbthomason/packer.nvim'
|
||||||
@ -18,6 +21,9 @@ require('packer').startup(function(use)
|
|||||||
'williamboman/mason.nvim',
|
'williamboman/mason.nvim',
|
||||||
'williamboman/mason-lspconfig.nvim',
|
'williamboman/mason-lspconfig.nvim',
|
||||||
|
|
||||||
|
'jose-elias-alvarez/null-ls.nvim',
|
||||||
|
'jay-babu/mason-null-ls.nvim',
|
||||||
|
|
||||||
-- Useful status updates for LSP
|
-- Useful status updates for LSP
|
||||||
'j-hui/fidget.nvim',
|
'j-hui/fidget.nvim',
|
||||||
|
|
||||||
@ -29,13 +35,13 @@ require('packer').startup(function(use)
|
|||||||
use { -- Autocompletion
|
use { -- Autocompletion
|
||||||
'hrsh7th/nvim-cmp',
|
'hrsh7th/nvim-cmp',
|
||||||
requires = {
|
requires = {
|
||||||
|
'onsails/lspkind.nvim',
|
||||||
'hrsh7th/cmp-nvim-lsp',
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
'L3MON4D3/LuaSnip',
|
'L3MON4D3/LuaSnip',
|
||||||
'saadparwaiz1/cmp_luasnip',
|
'saadparwaiz1/cmp_luasnip',
|
||||||
'hrsh7th/cmp-buffer', -- Buffer completion
|
'hrsh7th/cmp-buffer', -- Buffer completion
|
||||||
'hrsh7th/cmp-path', -- File path completion
|
'hrsh7th/cmp-path', -- File path completion
|
||||||
'hrsh7th/cmp-nvim-lua', -- Lua completion
|
'hrsh7th/cmp-nvim-lua', -- Lua completion
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +71,7 @@ require('packer').startup(function(use)
|
|||||||
|
|
||||||
-- Fuzzy Finder (files, lsp, etc)
|
-- Fuzzy Finder (files, lsp, etc)
|
||||||
use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } }
|
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
|
-- 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 }
|
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 {
|
use {
|
||||||
"zbirenbaum/copilot.lua",
|
"zbirenbaum/copilot.lua",
|
||||||
cmd = "Copilot",
|
cmd = "Copilot",
|
||||||
event = "InsertEnter",
|
event = "VimEnter",
|
||||||
config = function()
|
config = function()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
require("copilot").setup()
|
require("copilot").setup({
|
||||||
|
cmp = { enabled = true },
|
||||||
|
suggestion = { enabled = false },
|
||||||
|
panel = { enabled = false }
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
"zbirenbaum/copilot-cmp",
|
||||||
|
after = { "copilot.lua" },
|
||||||
|
module = "copilot_cmp",
|
||||||
|
config = function()
|
||||||
|
require("copilot_cmp").setup()
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
use 'majutsushi/tagbar'
|
use 'majutsushi/tagbar'
|
||||||
|
|
||||||
-- Parens
|
-- Parens
|
||||||
use 'jiangmiao/auto-pairs'
|
use {
|
||||||
|
"windwp/nvim-autopairs",
|
||||||
|
event = "InsertEnter",
|
||||||
|
config = function() require("nvim-autopairs").setup {} end
|
||||||
|
}
|
||||||
|
|
||||||
use 'tpope/vim-surround'
|
use 'tpope/vim-surround'
|
||||||
|
|
||||||
-- Todo comment highlight + diagnostics + navigation
|
-- Todo comment highlight + diagnostics + navigation
|
||||||
@ -323,12 +349,26 @@ require('gitsigns').setup {
|
|||||||
|
|
||||||
-- [[ Configure Telescope ]]
|
-- [[ Configure Telescope ]]
|
||||||
-- See `:help telescope` and `:help telescope.setup()`
|
-- See `:help telescope` and `:help telescope.setup()`
|
||||||
|
local action_layout = require("telescope.actions.layout")
|
||||||
require('telescope').setup {
|
require('telescope').setup {
|
||||||
defaults = {
|
defaults = {
|
||||||
mappings = {
|
mappings = {
|
||||||
|
n = {
|
||||||
|
["<M-p>"] = action_layout.toggle_preview
|
||||||
|
},
|
||||||
i = {
|
i = {
|
||||||
['<C-u>'] = false,
|
['<C-u>'] = false,
|
||||||
['<C-d>'] = 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
|
-- Enable telescope fzf native, if installed
|
||||||
pcall(require('telescope').load_extension, 'fzf')
|
pcall(require('telescope').load_extension, 'fzf')
|
||||||
|
|
||||||
|
require("telescope").load_extension("ui-select")
|
||||||
|
|
||||||
-- See `:help telescope.builtin`
|
-- See `:help telescope.builtin`
|
||||||
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
|
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' })
|
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
|
-- to define small helper and utility functions so you don't have to repeat yourself
|
||||||
|
|
||||||
if client.name == "ltex" then
|
if client.name == "ltex" then
|
||||||
print("loaded ltex extra")
|
|
||||||
require("ltex_extra").setup {
|
require("ltex_extra").setup {
|
||||||
load_langs = { "de-DE", "en-US" }, -- table <string> : languages for witch dictionaries will be loaded
|
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
|
init_check = true, -- boolean : whether to load dictionaries on startup
|
||||||
@ -504,9 +545,8 @@ local on_attach = function(client, bufnr)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- many times.
|
-- helpers.diagnostic_on_cursor_hold(bufnr)
|
||||||
-- 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.
|
|
||||||
local nmap = function(keys, func, desc)
|
local nmap = function(keys, func, desc)
|
||||||
if desc then
|
if desc then
|
||||||
desc = 'LSP: ' .. desc
|
desc = 'LSP: ' .. desc
|
||||||
@ -560,6 +600,7 @@ local servers = {
|
|||||||
pyright = {},
|
pyright = {},
|
||||||
bashls = {},
|
bashls = {},
|
||||||
ansiblels = {},
|
ansiblels = {},
|
||||||
|
dockerls = {},
|
||||||
marksman = {},
|
marksman = {},
|
||||||
rust_analyzer = {},
|
rust_analyzer = {},
|
||||||
yamlls = {},
|
yamlls = {},
|
||||||
@ -591,6 +632,16 @@ local servers = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local linters = {
|
||||||
|
shellcheck = {},
|
||||||
|
shfmt = {},
|
||||||
|
yamllint = {},
|
||||||
|
yamlfmt = {},
|
||||||
|
black = {},
|
||||||
|
hadolint = {}, -- Dockerfile
|
||||||
|
gitlint = {},
|
||||||
|
editorconfig_checker = {},
|
||||||
|
}
|
||||||
-- Setup neovim lua configuration
|
-- Setup neovim lua configuration
|
||||||
require('neodev').setup()
|
require('neodev').setup()
|
||||||
--
|
--
|
||||||
@ -603,6 +654,9 @@ require('mason').setup()
|
|||||||
|
|
||||||
-- Ensure the servers above are installed
|
-- Ensure the servers above are installed
|
||||||
local mason_lspconfig = require 'mason-lspconfig'
|
local mason_lspconfig = require 'mason-lspconfig'
|
||||||
|
local mason_null_ls = require 'mason-null-ls'
|
||||||
|
local null_ls = require 'null-ls'
|
||||||
|
|
||||||
|
|
||||||
mason_lspconfig.setup {
|
mason_lspconfig.setup {
|
||||||
ensure_installed = vim.tbl_keys(servers),
|
ensure_installed = vim.tbl_keys(servers),
|
||||||
@ -618,12 +672,31 @@ mason_lspconfig.setup_handlers {
|
|||||||
end,
|
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
|
-- Turn on lsp status information
|
||||||
require('fidget').setup()
|
require('fidget').setup()
|
||||||
|
|
||||||
-- nvim-cmp setup
|
-- nvim-cmp setup
|
||||||
local cmp = require 'cmp'
|
local cmp = require 'cmp'
|
||||||
local luasnip = require 'luasnip'
|
local luasnip = require 'luasnip'
|
||||||
|
local lspkind = require 'lspkind'
|
||||||
|
|
||||||
|
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
|
||||||
|
|
||||||
cmp.setup {
|
cmp.setup {
|
||||||
snippet = {
|
snippet = {
|
||||||
@ -631,13 +704,17 @@ cmp.setup {
|
|||||||
luasnip.lsp_expand(args.body)
|
luasnip.lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
window = {
|
||||||
|
completion = cmp.config.window.bordered(),
|
||||||
|
documentation = cmp.config.window.bordered(),
|
||||||
|
},
|
||||||
mapping = cmp.mapping.preset.insert {
|
mapping = cmp.mapping.preset.insert {
|
||||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
['<C-Space>'] = cmp.mapping.complete(),
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
['<CR>'] = cmp.mapping.confirm {
|
['<CR>'] = cmp.mapping.confirm {
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
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)
|
['<Tab>'] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
@ -658,13 +735,48 @@ cmp.setup {
|
|||||||
end
|
end
|
||||||
end, { 'i', 's' }),
|
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 = {
|
sources = {
|
||||||
|
{ name = 'copilot' },
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
{ name = 'luasnip' },
|
{ name = 'luasnip' },
|
||||||
{ name = 'buffer' },
|
{ name = 'buffer' },
|
||||||
{ name = 'path' },
|
{ name = 'path' },
|
||||||
{ name = 'nvim_lua' },
|
{ name = 'nvim_lua' },
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
nvim/lua/helpers.lua
Normal file
20
nvim/lua/helpers.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user