From fcb727cea08a308f0405d064782443a98a06425c Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Sun, 29 Jan 2023 00:27:05 +0100 Subject: [PATCH 1/5] [nvim] feat: add Telescope keymaps tk to list keymaps tx to list diagnostics --- .config/nvim/lua/maps.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index d137c60..881dff0 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -90,6 +90,16 @@ vim.keymap.set("n", "tl", function() require("telescope.builtin").live_grep() end, { desc = "Grep interactively" } ) +vim.keymap.set("n", "tk", + function() require("telescope.builtin").keymaps() end, + { desc = "Search through keymaps" } +) +vim.keymap.set("n", "tx", + function() require("telescope.builtin").diagnostics( + { buffnr = 0 } + ) end, + { desc = "Search through LSP diagnostics" } +) -- colorscheme vim.keymap.set("n", "s", From 173e84c089f5812ef2cb144f1cad44754c9c867d Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Sun, 29 Jan 2023 00:48:45 +0100 Subject: [PATCH 2/5] [nvim] fix: don't ask for luassert on attach --- .config/nvim/lua/plugin/lsp/sumneko_lua.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/nvim/lua/plugin/lsp/sumneko_lua.lua b/.config/nvim/lua/plugin/lsp/sumneko_lua.lua index 931db91..0905cab 100644 --- a/.config/nvim/lua/plugin/lsp/sumneko_lua.lua +++ b/.config/nvim/lua/plugin/lsp/sumneko_lua.lua @@ -34,6 +34,7 @@ M.setup = function(opts) -- 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 From 19af34b75d70f62b6ea5804ffe3c80330c9ed093 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Sun, 29 Jan 2023 01:09:12 +0100 Subject: [PATCH 3/5] [nvim] feat: switch to lazy.nvim !!! BREAKING: packer.nvim is not used anymore to get telescope-fzf-native.nvim working, run `:Lazy build telescope-fzf-native.nvim` --- .config/nvim/init.lua | 3 +- .config/nvim/lua/maps.lua | 4 +- .config/nvim/lua/plugin/cmp.lua | 95 ----------- .config/nvim/lua/plugin/colorscheme.lua | 17 ++ .config/nvim/lua/plugin/comment.lua | 64 ++------ .config/nvim/lua/plugin/completion.lua | 151 ++++++++++++++++++ .config/nvim/lua/plugin/init.lua | 20 +++ .config/nvim/lua/plugin/lsp/init.lua | 175 +++++++++++---------- .config/nvim/lua/plugin/luasnip.lua | 84 ---------- .config/nvim/lua/plugin/packer.lua | 125 --------------- .config/nvim/lua/plugin/telescope.lua | 40 +++-- .config/nvim/lua/plugin/treesitter.lua | 199 +++++++++++++----------- 12 files changed, 431 insertions(+), 546 deletions(-) delete mode 100644 .config/nvim/lua/plugin/cmp.lua create mode 100644 .config/nvim/lua/plugin/colorscheme.lua create mode 100644 .config/nvim/lua/plugin/completion.lua create mode 100644 .config/nvim/lua/plugin/init.lua delete mode 100644 .config/nvim/lua/plugin/luasnip.lua delete mode 100644 .config/nvim/lua/plugin/packer.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 23d4c4e..724dc35 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -6,6 +6,7 @@ require("globals") -- ./lua/globals.lua require("utils") -- ./lua/utils.lua require("settings") -- ./lua/settings.lua -require("plugin.packer") -- ./lua/plugin/packer.lua require("maps") -- ./lua/maps.lua require("statusline") -- ./lua/statusline.lua +require("plugin") +require("lazy").setup("plugin") diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index 881dff0..9f06f58 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -61,8 +61,8 @@ vim.keymap.set("n", "", -- packer vim.keymap.set("n", "u", - function() require("packer").sync() end, - { desc = "Sync packer config and update plugins" } + function() require("lazy").sync() end, + { desc = "Open up Lazy.nvim" } ) -- telescope diff --git a/.config/nvim/lua/plugin/cmp.lua b/.config/nvim/lua/plugin/cmp.lua deleted file mode 100644 index 7c45af8..0000000 --- a/.config/nvim/lua/plugin/cmp.lua +++ /dev/null @@ -1,95 +0,0 @@ --- Author : swytch --- Created : Saturday Sept. 11, 2021 22:12:33 CET --- License : GPLv3 --- Description : cmp plugin config file - -local cmp = require("cmp") -local luasnip = require("luasnip") - -local has_words_before = function() - 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 - --- Custom item icons -local icons = { } - -cmp.setup { - completion = { - autocomplete = true - }, - sources = { - { name = "path" }, - { name = "luasnip" }, - { name = "nvim_lsp" }, - { name = "buffer" }, - { name = "nvim_lua" }, - { name = "calc" }, - { name = "spell" }, - { name = "treesitter" }, - }, - formatting = { - format = function(entry, vim_item) - vim_item.menu = ({ - nvim_lsp = "[lsp]", - nvim_lua = "[nvim]", - luasnip = "[snip]", - path = "[path]", - buffer = "[buff]", - calc = "[calc]", - spell = "[spel]", - treesitter = "[tree]", - })[entry.source.name] - return vim_item - end, - }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = { - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping(function(fallback) - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { "i", "s" }), - }, - view = { - entries = {name = 'custom', selection_order = 'near_cursor' } - }, -} diff --git a/.config/nvim/lua/plugin/colorscheme.lua b/.config/nvim/lua/plugin/colorscheme.lua new file mode 100644 index 0000000..72bd820 --- /dev/null +++ b/.config/nvim/lua/plugin/colorscheme.lua @@ -0,0 +1,17 @@ +-- Author : swytch +-- Created : Sunday Jan. 29, 2023 00:50:17 CET +-- License : GPLv3 +-- Description : colorscheme config file + +local utils = require("utils") +local file = os.getenv("XDG_STATE_HOME") .. "/nvim_colorscheme" +local colorscheme = utils.lines_from(file)[0] + +return { + { + dir = "~/.local/src/astronomy.nvim", + opts = { + variant = colorscheme, + } + }, +} diff --git a/.config/nvim/lua/plugin/comment.lua b/.config/nvim/lua/plugin/comment.lua index c226f13..9c3ca2e 100644 --- a/.config/nvim/lua/plugin/comment.lua +++ b/.config/nvim/lua/plugin/comment.lua @@ -1,57 +1,21 @@ -- Author : swytch --- Created : Tuesday Oct. 12, 2021 19:07:36 CET +-- Created : Sunday Jan. 29, 2023 00:20:31 CET -- License : GPLv3 --- Description : Comment plugin config file +-- Description : Mini.comment plugin config file -require("Comment").setup { - ---Add a space b/w comment and the line - ---@type boolean - padding = true, +return { + "echasnovski/mini.comment", + version = "*", + opts = { + mappings = { + comment = "c", - ---Lines to be ignored while comment/uncomment. - ---Could be a regex string or a function that returns a regex string. - ---Example: Use '^$' to ignore empty lines - ---@type string|function - ignore = nil, + comment_line = "", - ---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode - ---@type table - mappings = { - ---operator-pending mapping - ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}` - basic = true, - ---extra mapping - ---Includes `gco`, `gcO`, `gcA` - extra = true, - ---extended mapping - ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}` - extended = false, + text_object = "gc", + }, }, - - ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode - ---@type table - toggler = { - ---line-comment toggle - line = "", - ---block-comment toggle - block = "bb", - }, - - ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode - ---@type table - opleader = { - ---line-comment opfunc mapping - line = "c", - ---block-comment opfunc mapping - block = "b", - }, - - ---Pre-hook, called before commenting the line - ---@type function|nil - pre_hook = nil, - - ---Post-hook, called after commenting is done - ---@type function|nil - post_hook = nil, + config = function(_, opts) + require("mini.comment").setup(opts) + end, } - diff --git a/.config/nvim/lua/plugin/completion.lua b/.config/nvim/lua/plugin/completion.lua new file mode 100644 index 0000000..71929a0 --- /dev/null +++ b/.config/nvim/lua/plugin/completion.lua @@ -0,0 +1,151 @@ +-- Author : swytch +-- Created : Sunday Jan. 29, 00:03:53 CET +-- License : GPLv3 +-- Description : completion plugin config file + +return { + { + "L3MON4D3/LuaSnip", + opts = function() + local types = require("luasnip.util.types") + return { + history = true, + -- Update more often, :h events for more info. + updateevents = "TextChanged,TextChangedI", + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "●", "LuaSnipChoice" } }, + }, + inactive = { + virt_text = { { "●", "LuaSnipInactive" } }, + }, + }, + [types.functionNode] = { + active = { + virt_text = { { "●", "LuaSnipFunction" } }, + }, + inactive = { + virt_text = { { "●", "LuaSnipInactive" } }, + }, + }, + [types.insertNode] = { + active = { + virt_text = { { "●", "LuaSnipInsert" } }, + }, + inactive = { + virt_text = { { "●", "LuaSnipInactive" } }, + }, + }, + }, + -- treesitter-hl has 100, use something higher (default is 200). + ext_base_prio = 200, + -- minimal increase in priority. + ext_prio_increase = 1, + enable_autosnippets = true, + } + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-calc", + "ray-x/cmp-treesitter", + "f3fora/cmp-spell", + }, + opts = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + + local has_words_before = function() + 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 + + return { + completion = { + autocomplete = true + }, + sources = { + { name = "path" }, + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "calc" }, + { name = "spell" }, + { name = "treesitter" }, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = "[lsp]", + nvim_lua = "[nvim]", + luasnip = "[snip]", + path = "[path]", + buffer = "[buff]", + calc = "[calc]", + spell = "[spel]", + treesitter = "[tree]", + })[entry.source.name] + return vim_item + end, + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { "i", "s" }), + }, + view = { + entries = { name = 'custom', selection_order = 'near_cursor' } + }, + } + end, + } +} diff --git a/.config/nvim/lua/plugin/init.lua b/.config/nvim/lua/plugin/init.lua new file mode 100644 index 0000000..cf83a5a --- /dev/null +++ b/.config/nvim/lua/plugin/init.lua @@ -0,0 +1,20 @@ +-- Author : swytch +-- Created : Friday Mar 12, 2021 22:28:34 CET +-- License : GPLv3 +-- Description : neovim packer config file + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +return {} + diff --git a/.config/nvim/lua/plugin/lsp/init.lua b/.config/nvim/lua/plugin/lsp/init.lua index ba49aa5..034730e 100644 --- a/.config/nvim/lua/plugin/lsp/init.lua +++ b/.config/nvim/lua/plugin/lsp/init.lua @@ -4,59 +4,7 @@ -- Description : neovim global lsp config file -local lspconfig = require("lspconfig") -local mason = require("mason") -local mason_lspconfig = require("mason-lspconfig") - -local globals = require("globals") -local signs = { - Error = globals.sign_error, - Warn = globals.sign_warn, - Hint = globals.sign_hint, - Info = globals.sign_info, -} - -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { - text = icon, - texthl = hl, - numhl = hl - }) -end - -vim.diagnostic.config({ - update_in_insert = true -}) - -local on_attach = function(_, bufnr) - local opts = { buffer = bufnr } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) - vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) - vim.keymap.set("n", "lf", vim.lsp.buf.format, opts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "wa", - vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set("n", "wr", - vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set("n", "wl", function() - vim.inspect(vim.lsp.buf.list_workspace_folders()) - end, opts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "so", - require("telescope.builtin").lsp_document_symbols, opts) -end - --- nvim-cmp supports additional completion capabilities -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) +_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin" local servers = { "clangd", @@ -65,31 +13,98 @@ local servers = { "texlab", } -mason.setup({ - ui = { - icons = { - server_installed = "✓", - server_pending = "o", - server_uninstalled = "" +return { + + { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, + config = function() + + vim.diagnostic.config({ + underline = true, + update_in_insert = false, + severity_sort = true, + }) + + local lspconfig = require("lspconfig") + local globals = require("globals") + + local signs = { + Error = globals.sign_error, + Warn = globals.sign_warn, + Hint = globals.sign_hint, + Info = globals.sign_info, + } + + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { + text = icon, + texthl = hl, + numhl = hl + }) + end + + local on_attach = function(_, bufnr) + local opts = { buffer = bufnr } + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) + vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) + vim.keymap.set("n", "lf", vim.lsp.buf.format, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", + vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", + vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", function() + vim.inspect(vim.lsp.buf.list_workspace_folders()) + end, opts) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "so", + require("telescope.builtin").lsp_document_symbols, opts) + end + + -- nvim-cmp supports additional completion capabilities + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + + for _, server in ipairs(servers) do + local opts = { + on_attach = on_attach, + capabilities = capabilities, + } + + local plugin = string.format("plugin.lsp.%s", server) + require(plugin).setup(opts) + + lspconfig[server].setup(opts) + end + + require("mason-lspconfig").setup({ ensure_installed = servers }) + end + }, + { + + "williamboman/mason.nvim", + cmd = "Mason", + -- opts = { ensure_installed = servers }, + opts = { + ui = { + icons = { + server_installed = "✓", + server_pending = "o", + server_uninstalled = "" + } + } } - } -}) - -_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin" - -mason_lspconfig.setup({ - ensure_installed = servers, -}) - - -for _, server in ipairs(servers) do - local opts = { - on_attach = on_attach, - capabilities = capabilities, - } - - local plugin = string.format("plugin.lsp.%s", server) - require(plugin).setup(opts) - - lspconfig[server].setup(opts) -end + }, +} diff --git a/.config/nvim/lua/plugin/luasnip.lua b/.config/nvim/lua/plugin/luasnip.lua deleted file mode 100644 index a3645f3..0000000 --- a/.config/nvim/lua/plugin/luasnip.lua +++ /dev/null @@ -1,84 +0,0 @@ --- Author : swytch --- Created : Friday Nov. 19, 2021 23:27:24 CET --- License : GPLv3 --- Description : luasnip config file - -local ls = require("luasnip") --- some shorthands... -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node -local i = ls.insert_node -local f = ls.function_node -local c = ls.choice_node -local d = ls.dynamic_node -local l = require("luasnip.extras").lambda -local r = require("luasnip.extras").rep -local p = require("luasnip.extras").partial -local m = require("luasnip.extras").match -local n = require("luasnip.extras").nonempty -local dl = require("luasnip.extras").dynamic_lambda -local fmt = require("luasnip.extras.fmt").fmt -local fmta = require("luasnip.extras.fmt").fmta -local types = require("luasnip.util.types") -local conds = require("luasnip.extras.expand_conditions") - --- Every unspecified option will be set to the default. -ls.config.set_config({ - history = true, - -- Update more often, :h events for more info. - updateevents = "TextChanged,TextChangedI", - ext_opts = { - [types.choiceNode] = { - active = { - virt_text = { { "●", "LuaSnipChoice" } }, - }, - inactive = { - virt_text = { { "●", "LuaSnipInactive" } }, - }, - }, - [types.functionNode] = { - active = { - virt_text = { { "●", "LuaSnipFunction" } }, - }, - inactive = { - virt_text = { { "●", "LuaSnipInactive" } }, - }, - }, - [types.insertNode] = { - active = { - virt_text = { { "●", "LuaSnipInsert" } }, - }, - inactive = { - virt_text = { { "●", "LuaSnipInactive" } }, - }, - }, - }, - -- treesitter-hl has 100, use something higher (default is 200). - ext_base_prio = 200, - -- minimal increase in priority. - ext_prio_increase = 1, - enable_autosnippets = true, -}) - --- Make sure to not pass an invalid command, as io.popen() may write over nvim-text. -local function bash(_, _, command) - local file = io.popen(command, "r") - local res = {} - for line in file:lines() do - table.insert(res, line) - end - return res -end - --- Returns a snippet_node wrapped around an insert_node whose initial --- text value is set to the current date in the desired format. -local function date_input(fmt) - local format = fmt or "%Y-%m-%d" - return sn(nil, i(1, os.date(format))) -end - --- in a lua file: search lua-, then c-, then all-snippets. -ls.filetype_extend("lua", { "c" }) --- in a cpp file: search c-snippets, then all-snippets only (no cpp-snippets!!). -ls.filetype_set("cpp", { "c" }) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua deleted file mode 100644 index 2a774c6..0000000 --- a/.config/nvim/lua/plugin/packer.lua +++ /dev/null @@ -1,125 +0,0 @@ --- Author : swytch --- Created : Friday Mar 12, 2021 22:28:34 CET --- License : GPLv3 --- Description : neovim packer config file - - -local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - print("Cloning packer...") - PACKER_BOOTSTRAP = vim.fn.system({ - "git", - "clone", - "--depth", - "1", - "https://github.com/wbthomason/packer.nvim", - install_path, - }) - vim.cmd([[packadd packer.nvim]]) - print("Done.") -end - -local packer = require("packer") - -packer.init({ - display = { - working_sym = ' ', -- The symbol for a plugin being installed/updated - error_sym = ' ', -- The symbol for a plugin with an error in installation/updating - done_sym = ' ', -- The symbol for a plugin which has completed installation/updating - removed_sym = '- ', -- The symbol for an unused plugin which was removed - moved_sym = '→ ', -- The symbol for a plugin which was moved (e.g. from opt to start) - header_sym = '━ ', -- The symbol for the header line in packer's display - open_fn = function() - return require('packer.util').float({ border = "single" }) - end, -- Display in a floating window - }, -}) - -local use = packer.use - -return require("packer").startup(function() - -- packer manages itself - use "wbthomason/packer.nvim" - - -- colorscheme - use { - "~/.local/src/astronomy.nvim", - config = function() require("colorscheme") end - } - - -- tree-sitter - use { - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - config = function() require("plugin.treesitter") end - } - - use { -- Additional text objects via treesitter - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter', - } - - -- telescope - use { - "nvim-telescope/telescope.nvim", - requires = { - { - "nvim-lua/plenary.nvim", - }, - { - "nvim-telescope/telescope-fzf-native.nvim", - run = "make" - }, - { - "nvim-telescope/telescope-file-browser.nvim", - } - }, - config = function() - require("telescope") - require("telescope").load_extension("fzf") - require("telescope").load_extension("file_browser") - end - } - - -- LSP - use { - "neovim/nvim-lspconfig", - requires = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - }, - config = function() require("plugin.lsp") end - } - - -- auto completion - use { - "hrsh7th/nvim-cmp", - requires = { - { - "L3MON4D3/LuaSnip", - config = function() - require("plugin.luasnip") end - }, - "saadparwaiz1/cmp_luasnip", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-calc", - "ray-x/cmp-treesitter", - "f3fora/cmp-spell", - }, - config = function() require("plugin.cmp") end - } - - -- commenting, simplified - use { - "numToStr/Comment.nvim", - config = function() require("plugin.comment") end - } - - -- automatically setup the config after cloning - if PACKER_BOOTSTRAP then - require("packer").sync() - end -end) diff --git a/.config/nvim/lua/plugin/telescope.lua b/.config/nvim/lua/plugin/telescope.lua index 10c1cad..e7d82a7 100644 --- a/.config/nvim/lua/plugin/telescope.lua +++ b/.config/nvim/lua/plugin/telescope.lua @@ -1,22 +1,32 @@ -- Author : swytch -- Created : Monday Dec. 26, 2022 18:39:16 CET -- License : GPLv3 --- Description : treesitter config file +-- Description : telescope config file -require("telescope").setup { - extensions = { - file_browser = { - theme = "ivy", - -- disables netrw and use telescope-file-browser in its place - hijack_netrw = true, - mappings = { - ["i"] = { - -- your custom insert mode mappings - }, - ["n"] = { - -- your custom normal mode mappings - }, +return { + "nvim-telescope/telescope.nvim", + dependencies = { + { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-file-browser.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + lazy = false, }, - }, + } }, + opts = { + extensions = { + file_browser = { + theme = "ivy", + hijack_netrw = true, + } + } + }, + config = function(_, opts) + require("telescope").setup(opts) + require("telescope").load_extension("fzf") + require("telescope").load_extension("file_browser") + end } diff --git a/.config/nvim/lua/plugin/treesitter.lua b/.config/nvim/lua/plugin/treesitter.lua index 314c6f8..766db28 100644 --- a/.config/nvim/lua/plugin/treesitter.lua +++ b/.config/nvim/lua/plugin/treesitter.lua @@ -3,113 +3,124 @@ -- License : GPLv3 -- Description : treesitter config file -require("nvim-treesitter.configs").setup { - ensure_installed = { "c", "lua", "rust", "bash", "vim" }, - highlight = { - enable = true, +return { + "nvim-treesitter/nvim-treesitter", + dependencies = { + -- Additional text objects via treesitter + "nvim-treesitter/nvim-treesitter-textobjects", }, - indent = { - enable = true, - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = "", - node_decremental = "", - }, - }, - textobjects = { - select = { + build = ":TSUpdate", + opts = { + ensure_installed = { "c", "lua", "rust", "bash", "vim" }, + highlight = { + enable = true, + }, + indent = { + enable = true, + }, + incremental_selection = { enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { - -- use the capture groups defined in textobjects.scm - ["ap"] = { - query = "@parameter.outer", - desc = "Select parameter region" - }, - ["ip"] = { - query = "@parameter.inner", - desc = "Select inner part of a parameter region" - }, - ["af"] = { - query = "@function.outer", - desc = "Select a function block" - }, - ["if"] = { - query = "@function.inner", - desc = "Select inner part of a function" - }, - ["ac"] = { - query = "@class.outer", - desc = "Select a class block" - }, - ["ic"] = { - query = "@class.inner", - desc = "Select inner part of a class" - }, + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", }, }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - ["]m"] = { - query = "@function.outer", - desc = "Jump to next function", - }, - ["])"] = { - query = "@class.outer", - desc = "Jump to next class", + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- use the capture groups defined in textobjects.scm + ["ap"] = { + query = "@parameter.outer", + desc = "Select parameter region" + }, + ["ip"] = { + query = "@parameter.inner", + desc = "Select inner part of a parameter region" + }, + ["af"] = { + query = "@function.outer", + desc = "Select a function block" + }, + ["if"] = { + query = "@function.inner", + desc = "Select inner part of a function" + }, + ["ac"] = { + query = "@class.outer", + desc = "Select a class block" + }, + ["ic"] = { + query = "@class.inner", + desc = "Select inner part of a class" + }, }, }, - goto_next_end = { - ["]M"] = { - query = "@function.outer", - desc = "Jump after next function", + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = { + query = "@function.outer", + desc = "Jump to next function", + }, + ["])"] = { + query = "@class.outer", + desc = "Jump to next class", + }, }, - ["]]"] = { - query = "@class.outer", - desc = "Jump after next class", + goto_next_end = { + ["]M"] = { + query = "@function.outer", + desc = "Jump after next function", + }, + ["]]"] = { + query = "@class.outer", + desc = "Jump after next class", + }, + }, + goto_previous_start = { + ["[m"] = { + query = "@function.outer", + desc = "Jump to previous function", + }, + ["[)"] = { + query = "@class.outer", + desc = "Jump to previous class", + }, + }, + goto_previous_end = { + ["[M"] = { + query = "@function.outer", + desc = "Jump after previous function", + }, + ["[]"] = { + query = "@class.outer", + desc = "Jump after previous class", + }, }, }, - goto_previous_start = { - ["[m"] = { - query = "@function.outer", - desc = "Jump to previous function", + swap = { + enable = true, + swap_next = { + ["a"] = { + query = "@parameter.inner", + desc = "Swap with next parameter", + }, }, - ["[)"] = { - query = "@class.outer", - desc = "Jump to previous class", - }, - }, - goto_previous_end = { - ["[M"] = { - query = "@function.outer", - desc = "Jump after previous function", - }, - ["[]"] = { - query = "@class.outer", - desc = "Jump after previous class", - }, - }, - }, - swap = { - enable = true, - swap_next = { - ["a"] = { - query = "@parameter.inner", - desc = "Swap with next parameter", - }, - }, - swap_previous = { - ["A"] = { - query = "@parameter.inner", - desc = "Swap with previous parameter", + swap_previous = { + ["A"] = { + query = "@parameter.inner", + desc = "Swap with previous parameter", + }, }, }, }, }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end } From 58f2ddf866f0a5cd0938123ca94cc5b032aa7b00 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Fri, 3 Feb 2023 09:18:19 +0100 Subject: [PATCH 4/5] [nvim] cleanup: telescope.lua layout --- .config/nvim/lua/plugin/telescope.lua | 47 ++++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/.config/nvim/lua/plugin/telescope.lua b/.config/nvim/lua/plugin/telescope.lua index e7d82a7..b977ba2 100644 --- a/.config/nvim/lua/plugin/telescope.lua +++ b/.config/nvim/lua/plugin/telescope.lua @@ -4,29 +4,30 @@ -- Description : telescope config file return { - "nvim-telescope/telescope.nvim", - dependencies = { - { - "nvim-lua/plenary.nvim", - "nvim-telescope/telescope-file-browser.nvim", + { + "nvim-telescope/telescope.nvim", + dependencies = { { - "nvim-telescope/telescope-fzf-native.nvim", - build = "make", - lazy = false, - }, - } - }, - opts = { - extensions = { - file_browser = { - theme = "ivy", - hijack_netrw = true, + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-file-browser.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make" + } } - } - }, - config = function(_, opts) - require("telescope").setup(opts) - require("telescope").load_extension("fzf") - require("telescope").load_extension("file_browser") - end + }, + opts = { + extensions = { + file_browser = { + theme = "ivy", + hijack_netrw = true, + } + } + }, + config = function(_, opts) + require("telescope").setup(opts) + require("telescope").load_extension("fzf") + require("telescope").load_extension("file_browser") + end + } } From 2efc69cc16b2bf0ecd78dbf5dba37ec6f6f0538a Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Fri, 3 Feb 2023 09:18:39 +0100 Subject: [PATCH 5/5] [nvim] feat: add TreeSitter parses for C++, Python, LaTeX --- .config/nvim/lua/plugin/treesitter.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.config/nvim/lua/plugin/treesitter.lua b/.config/nvim/lua/plugin/treesitter.lua index 766db28..6b65232 100644 --- a/.config/nvim/lua/plugin/treesitter.lua +++ b/.config/nvim/lua/plugin/treesitter.lua @@ -11,7 +11,9 @@ return { }, build = ":TSUpdate", opts = { - ensure_installed = { "c", "lua", "rust", "bash", "vim" }, + ensure_installed = { + "c", "cpp", "lua", "rust", "bash", "vim", "latex", "python", + }, highlight = { enable = true, },