From 6b3424c590adf65db5ac8138a073394cf3c66fa9 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Wed, 22 Nov 2023 01:25:43 -0500 Subject: [PATCH] separated plugins configs and added couple new plugins --- init.lua | 25 ++---- lua/config/mappings.lua | 21 ++++- lua/config/options.lua | 48 ++++------- lua/config/utils.lua | 1 + lua/custom/plugins/{nvim-cmp.lua => cmp.lua} | 67 ++++++++++++-- lua/custom/plugins/lsp-config.lua | 91 +++++++++----------- lua/custom/plugins/telescope-undo.lua | 34 ++++++++ lua/custom/plugins/telescope.lua | 7 +- lua/custom/plugins/undotree.lua | 8 +- lua/custom/plugins/venv-selector.lua | 1 - lua/custom/plugins/which-key.lua | 13 ++- 11 files changed, 201 insertions(+), 115 deletions(-) rename lua/custom/plugins/{nvim-cmp.lua => cmp.lua} (50%) create mode 100644 lua/custom/plugins/telescope-undo.lua diff --git a/init.lua b/init.lua index 087f745f..4efc851a 100644 --- a/init.lua +++ b/init.lua @@ -1,11 +1,10 @@ --- See `:help mapleader` --- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) +-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Install package manager --- https://github.com/folke/lazy.nvim --- `:help lazy.nvim.txt` for more info +-- https://github.com/folke/lazy.nvim +-- Check Lua documentation for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system { @@ -33,19 +32,13 @@ require('lazy').setup({ -- Detect tabstop and shiftwidth automatically 'tpope/vim-sleuth', - { import = 'custom.plugins' }, + { + import = 'custom.plugins', + exclude = 'custom.plugins.mason', + }, }, opts) require('config.options') require('config.mappings') - --- [[ Highlight on yank ]] --- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) -vim.api.nvim_create_autocmd('TextYankPost', { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, - pattern = '*', -}) +require('config.utils') +require('config.themes') diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua index b7626fdd..88c3b116 100644 --- a/lua/config/mappings.lua +++ b/lua/config/mappings.lua @@ -10,7 +10,9 @@ vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { - expr = true, silent = true + -- Unmap the 'gp' key for previous word + expr = true, + silent = true }) -- Move lines @@ -24,6 +26,8 @@ vim.keymap.set('n', '', "zz", { desc = "Half Page Jumping Down" }) -- Keep search line in the middle vim.keymap.set('n', 'n', 'nzzzv', { silent = true }) vim.keymap.set('n', 'N', 'Nzzzv', { silent = true }) +-- Unmap the 'p' key for previous word +vim.api.nvim_set_keymap('n', 'gp', '', { noremap = true, silent = true }) -- Quick fix navigation vim.keymap.set("n", "", "cnextzz") @@ -36,8 +40,8 @@ vim.keymap.set({ 'n', 'v' }, 'y', "\"+y", { desc = "Copy to + register" vim.keymap.set('n', 'Y', "\"+Y") -- Replace current word -vim.keymap.set("n", "s", [[:%s/\<\>//gI]], - { desc = "[S]ubstitute Current Word" }) +vim.keymap.set("n", "r", [[:%s/\<\>//gI]], + { desc = "[R]eplace Current Word" }) vim.keymap.set("n", "x", "!chmod +x %", { desc = "Set Current File to Executable", silent = true }) -- [ telescope keymaps] @@ -69,3 +73,14 @@ vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous dia vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) + +-- [[ Highlight on yank ]] +-- See `:help vim.highlight.on_yank()` +local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) +vim.api.nvim_create_autocmd('TextYankPost', { + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, + pattern = '*', +}) diff --git a/lua/config/options.lua b/lua/config/options.lua index 190f9ccc..75e3f8d1 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -1,15 +1,13 @@ local opt = vim.opt local g = vim.g + local opts = { - -- change cursor in insert mode + -- Change cursor in insert mode guicursor = "", -- Make line numbers default relativenumber = true, - -- Enable mouse mode - mouse = 'a', - -- Enable break indent breakindent = true, @@ -18,16 +16,15 @@ local opts = { softtabstop = 4, shiftwidth = 4, expandtab = true, - smartindent = true, -- Disable line wrap wrap = false, - -- Save undo history_list + -- Save undo history swapfile = false, backup = false, - undodir = os.getenv("HOME") .. "/.vim/undodir", + undodir = vim.fn.stdpath("data") .. "/site/undodir", undofile = true, -- Searching Configuration @@ -48,14 +45,12 @@ local opts = { -- NOTE: You should make sure your terminal supports this termguicolors = true, scrolloff = 10, - -- isfname:append("@-@"), colorcolumn = "80", - -- part of the neovim imprioving command below - pyxversion = 3 + pyxversion = 3, } for k, v in pairs(opts) do - vim.opt[k] = v + opt[k] = v end local win_local = { @@ -67,7 +62,7 @@ for k, v in pairs(win_local) do vim.wo[k] = v end --- disable builtins plugins +-- Disable built-in plugins local disabled_built_ins = { "2html_plugin", "getscript", @@ -75,12 +70,12 @@ local disabled_built_ins = { "gzip", "logipat", "matchit", - -- "netrw", + -- "netrw", "netrwFileHandlers", "loaded_remote_plugins", "loaded_tutor_mode_plugin", - "netrwPlugin", - "netrwSettings", + -- "netrwPlugin", + -- "netrwSettings", "rrhelper", "spellfile_plugin", "tar", @@ -89,31 +84,27 @@ local disabled_built_ins = { "vimballPlugin", "zip", "zipPlugin", - "matchparen", -- matchparen.nvim disables the default + "matchparen", } for _, plugin in pairs(disabled_built_ins) do - vim.g["loaded_" .. plugin] = 1 + g["loaded_" .. plugin] = 1 end --- --- IMPROVE NEOVIM STARTUP --- https://github.com/editorconfig/editorconfig-vim/issues/50 +-- Improve Neovim startup local global_let_opts = { - loaded_python_provier = 0, + loaded_python_provider = 0, loaded_python3_provider = 0, python_host_skip_check = 1, - -- python_host_prog = '/bin/python2', python3_host_skip_check = 1, python3_host_prog = '/usr/local/bin/python3', EditorConfig_core_mode = 'external_command', - -- https://vi.stackexchange.com/a/5318/7339 matchparen_timeout = 20, matchparen_insert_timeout = 20, } for k, v in pairs(global_let_opts) do - vim.g[k] = v + g[k] = v end opt.formatoptions = "l" @@ -126,12 +117,3 @@ opt.formatoptions = opt.formatoptions + "n" -- Indent past the formatlistpat, not underneath it. + "j" -- Auto-remove comments if possible. - "2" -- I'm not in gradeschool anymore - -opt.guicursor = { - "n-v:block", - "i-c-ci-ve:ver25", - "r-cr:hor20", - "o:hor50", - "i:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor", - "sm:block-blinkwait175-blinkoff150-blinkon175", -} diff --git a/lua/config/utils.lua b/lua/config/utils.lua index e69de29b..8b137891 100644 --- a/lua/config/utils.lua +++ b/lua/config/utils.lua @@ -0,0 +1 @@ + diff --git a/lua/custom/plugins/nvim-cmp.lua b/lua/custom/plugins/cmp.lua similarity index 50% rename from lua/custom/plugins/nvim-cmp.lua rename to lua/custom/plugins/cmp.lua index 82b81850..b7126dac 100644 --- a/lua/custom/plugins/nvim-cmp.lua +++ b/lua/custom/plugins/cmp.lua @@ -14,21 +14,48 @@ return { }, config = function() -- See `:help cmp` + vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } + require('luasnip.loaders.from_vscode').lazy_load() + local cmp = require 'cmp' local luasnip = require 'luasnip' - require('luasnip.loaders.from_vscode').lazy_load() luasnip.config.setup {} + local select_opts = { behavior = cmp.SelectBehavior.Select } + cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, + sources = { + { name = 'path' }, + { name = 'nvim_lsp', keyword_length = 1 }, + { name = 'buffer', keyword_length = 3 }, + { name = 'luasnip', keyword_length = 2 }, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = { 'menu', 'abbr', 'kind' }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { @@ -54,10 +81,38 @@ return { end end, { 'i', 's' }), }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, } + + local sign = function(opts) + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' + }) + end + + sign({ name = 'DiagnosticSignError', text = '✘' }) + sign({ name = 'DiagnosticSignWarn', text = '▲' }) + sign({ name = 'DiagnosticSignHint', text = '⚑' }) + sign({ name = 'DiagnosticSignInfo', text = '»' }) + + vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + }, + }) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + { border = 'rounded' } + ) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + { border = 'rounded' } + ) end, } diff --git a/lua/custom/plugins/lsp-config.lua b/lua/custom/plugins/lsp-config.lua index f5a22a7a..d1b5b470 100644 --- a/lua/custom/plugins/lsp-config.lua +++ b/lua/custom/plugins/lsp-config.lua @@ -60,17 +60,24 @@ return { -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() - end, { desc = 'Format current buffer with LSP' }) + end, { desc = 'Format current buffer with LSP and lint' }) -- Enable auto-formatting on save - vim.api.nvim_command([[ - augroup AutoFormatOnSave - autocmd! - autocmd BufWritePre * :Format - augroup END - ]]) + -- vim.api.nvim_command([[ + -- augroup AutoFormatOnSave + -- autocmd! + -- autocmd BufWritePre * :Format + -- augroup END + -- ]]) end + -- Setup neovim lua configuration + require('neodev').setup() + + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + local capabilities = require('cmp_nvim_lsp').default_capabilities() + + -- Servers configuration local servers = { clangd = {}, gopls = { @@ -82,7 +89,7 @@ return { completeUnimported = true, usePlaceholders = true, analysis = { - unusedarams = true, + unusedParams = true, }, }, }, @@ -91,46 +98,39 @@ return { settings = { pylsp = { plugins = { - pycodestyle = { - ignore = { 'W391' }, - maxLineLength = 79 + black = { + blackArgs = { + "--line-length", "79", + "--exclude", "venv", + "--exclude", "env", + "--exclude", ".git", + "--exclude", ".hg", + }, + lineLength = 79, }, flake8 = {}, - black = { - lineLength = 79, - -- Configure Black to split lines without specifying a target version - blackArgs = { - "--line-length", - "79", - "--exclude", - "venv", - "--exclude", - "env", - "--exclude", - ".git", - "--exclude", - ".hg", - }, + isort = { + profile = "black", }, mypy = { - enabled = true, - command = 'mypy', args = {}, + command = "mypy", diagnostics = true, + enabled = true, }, - isort = { - profile = 'black', + pycodestyle = { + ignore = { "W391" }, + maxLineLength = 79, }, }, python = { - -- Specify the path to your Python interpreter - pythonPath = "/usr/bin/python3", analysis = { autoSearchPaths = true, - diagnosticMode = 'openFilesOnly', + diagnosticMode = "openFilesOnly", + typeCheckingMode = "strict", useLibraryCodeForTypes = true, - typeCheckingMode = 'on', }, + pythonPath = "/usr/local/bin/python3", }, }, }, @@ -138,7 +138,6 @@ return { -- rust_analyzer = {}, -- tsserver = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, - lua_ls = { Lua = { workspace = { checkThirdParty = false }, @@ -147,16 +146,8 @@ return { }, } - -- Setup neovim lua configuration - require('neodev').setup() - - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - - -- Setup Mason condifuration - local mason = require 'mason' - + -- Setup Mason configuration + local mason = require('mason') mason.setup { ui = { icons = { @@ -166,13 +157,14 @@ return { }, }, } - -- Ensure the servers above are installed - local mason_lspconfig = require 'mason-lspconfig' + -- Ensure the servers above are installed + local mason_lspconfig = require('mason-lspconfig') mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers) + ensure_installed = vim.tbl_keys(servers), } + -- Add Mason handlers mason_lspconfig.setup_handlers { function(server_name) require('lspconfig')[server_name].setup { @@ -183,5 +175,8 @@ return { } end } + + -- Load nvim-cmp after Mason to allow Mason to configure it first + require('cmp') end } diff --git a/lua/custom/plugins/telescope-undo.lua b/lua/custom/plugins/telescope-undo.lua new file mode 100644 index 00000000..b585e565 --- /dev/null +++ b/lua/custom/plugins/telescope-undo.lua @@ -0,0 +1,34 @@ +return { + "debugloop/telescope-undo.nvim", + dependencies = { -- note how they're inverted to above example + { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + }, + keys = { + { -- lazy style key map + "u", + "Telescope undo", + desc = "undo history", + }, + }, + opts = { + extensions = { + undo = { + side_by_side = true, + layout_strategy = "vertical", + layout_config = { + preview_height = 0.8, + }, + }, + }, + }, + config = function(_, opts) + -- Calling telescope's setup from multiple specs does not hurt, it will happily merge the + -- configs for us. We won't use data, as everything is in it's own namespace (telescope + -- defaults, as well as each extension). + require("telescope").setup(opts) + require("telescope").load_extension("undo") + end, +} diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua index baf8fcb8..011384c1 100644 --- a/lua/custom/plugins/telescope.lua +++ b/lua/custom/plugins/telescope.lua @@ -4,6 +4,7 @@ return { branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', + 'debugloop/telescope-undo.nvim', -- Fuzzy Finder Algorithm which requires local dependencies to be built. -- Only load if `make` is available. Make sure you have the system -- requirements installed. @@ -19,7 +20,7 @@ return { 'nvim-tree/nvim-web-devicons', }, config = function() - require('telescope').setup { + require('telescope').setup({ defaults = { mappings = { i = { @@ -28,7 +29,7 @@ return { }, }, }, - } + }) -- Enable telescope fzf native, if installed pcall(require('telescope').load_extension, 'fzf') @@ -68,5 +69,7 @@ return { end vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) + + -- require("telescope").extensions.undo.undo() end, } diff --git a/lua/custom/plugins/undotree.lua b/lua/custom/plugins/undotree.lua index a61d00b9..c5d4ad9a 100644 --- a/lua/custom/plugins/undotree.lua +++ b/lua/custom/plugins/undotree.lua @@ -1,6 +1,6 @@ return { - 'mbbill/undotree', - config = function() - vim.keymap.set('n', 'u', vim.cmd.UndotreeToggle, { desc = '[U]ndotree' }) - end + -- 'mbbill/undotree', + -- config = function() + -- vim.keymap.set('n', 'u', vim.cmd.UndotreeToggle, { desc = '[U]ndotree' }) + -- end } diff --git a/lua/custom/plugins/venv-selector.lua b/lua/custom/plugins/venv-selector.lua index f604fd89..17f7b8ab 100644 --- a/lua/custom/plugins/venv-selector.lua +++ b/lua/custom/plugins/venv-selector.lua @@ -43,4 +43,3 @@ return { end end } - diff --git a/lua/custom/plugins/which-key.lua b/lua/custom/plugins/which-key.lua index 35e24efb..6f820e0f 100644 --- a/lua/custom/plugins/which-key.lua +++ b/lua/custom/plugins/which-key.lua @@ -1,4 +1,13 @@ return { - 'folke/which-key.nvim', - opts = {} + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } }