From cb36ccfa8db66db953795fd8e22138ed1712b1cd Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 18 Sep 2024 00:58:26 +0200 Subject: checkpoint - added basic luasnip configuration - added highlights for TODO and FIXME keywords - added incremental selection of treesitter - added prettier to conform formatters - added when_disabled function to disable pairs in comments - changed the hiding keybind to :Hide command - only enable ` pairs in markdown - removed keybind - removed cmp's calc source - renamed keybinds for consistency - reorganized plugins in lazy.lua --- after/plugin/autoclose.lua | 14 +++- after/plugin/conform.lua | 1 + after/plugin/luasnip.lua | 31 +++++++++ after/plugin/telescope.lua | 2 +- after/plugin/treesitter.lua | 7 ++ lua/config/lazy.lua | 151 ++++++++++++++++++++------------------------ lua/config/lsp.lua | 27 +++++--- lua/config/map.lua | 24 ++++--- lua/config/set.lua | 3 + todo.md | 3 + 10 files changed, 158 insertions(+), 105 deletions(-) create mode 100644 after/plugin/luasnip.lua diff --git a/after/plugin/autoclose.lua b/after/plugin/autoclose.lua index b742fc6..1c912da 100644 --- a/after/plugin/autoclose.lua +++ b/after/plugin/autoclose.lua @@ -1,3 +1,14 @@ +local function in_comment() + if + require("cmp.config.context").in_treesitter_capture("comment") == true + or require("cmp.config.context").in_syntax_group("Comment") + then + return true + else + return false + end +end + local filetypes = require("autoclose").setup({ keys = { ["("] = { escape = false, close = true, pair = "()" }, @@ -18,12 +29,13 @@ local filetypes = require("autoclose").setup({ close = true, pair = "''", disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive", "markdown" }, + disabled_when = in_comment, }, ["`"] = { escape = true, close = true, pair = "``", - disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive" }, + enabled_fileptypes = { "markdown" }, }, ["*"] = { escape = true, close = true, pair = "**", enabled_filetypes = { "markdown" } }, ["_"] = { escape = true, close = true, pair = "__", enabled_filetypes = { "markdown" } }, diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua index 13961b6..76f7dca 100644 --- a/after/plugin/conform.lua +++ b/after/plugin/conform.lua @@ -1,6 +1,7 @@ require("conform").setup({ formatters_by_ft = { lua = { "stylua" }, + html = { "prettier" }, }, format_on_save = { -- These options will be passed to conform.format() diff --git a/after/plugin/luasnip.lua b/after/plugin/luasnip.lua new file mode 100644 index 0000000..e14a1a5 --- /dev/null +++ b/after/plugin/luasnip.lua @@ -0,0 +1,31 @@ +local ls = require("luasnip") +local s = ls.snippet +local i = ls.insert_node +local t = ls.text_node + +local map = vim.keymap.set + +map("i", "", function() + if ls.expand_or_locally_jumpable() then + ls.expand_or_jump() + end +end, { silent = true }) +map({ "i", "s" }, "", function() + ls.locally_jumpable(-1) +end, { silent = true }) +map({ "i", "s" }, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end, { silent = true }) + +-- temporary keybind to play around +map("n", " s", "source ~/.config/nvim/after/plugin/luasnip.lua") + +ls.config.set_config({ + history = true, +}) + +ls.add_snippets("all", { + ls.parser.parse_snippet("expand", "-- this is $1 expanded $2 $3!"), +}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index c2d32a3..720e157 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -25,7 +25,7 @@ require("telescope").setup({ local builtin = require("telescope.builtin") map("n", " tf", builtin.find_files) -map("n", " tb", builtin.buffers) +map("n", " bl", builtin.buffers) map("n", "", builtin.git_files) map("n", " tw", builtin.live_grep) map("n", " th", builtin.help_tags, { desc = "Find help tags" }) diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua index 1eb6fa5..83eb7cf 100644 --- a/after/plugin/treesitter.lua +++ b/after/plugin/treesitter.lua @@ -7,4 +7,11 @@ require("nvim-treesitter.configs").setup({ enable = true, additional_vim_regex_highlighting = false, }, + incremental_selection = { + enable = true, + keymaps = { + node_incremental = "v", + node_decremental = "V", + }, + }, }) diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index 1bdad47..3cbe77c 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -14,68 +14,68 @@ vim.opt.rtp:prepend(lazypath) -- plugins installation and configuration require("lazy").setup({ - -- lsp setup + "echasnovski/mini.nvim", + "lewis6991/gitsigns.nvim", + "tpope/vim-vinegar", + "tpope/vim-eunuch", + "mg979/vim-visual-multi", + "jghauser/follow-md-links.nvim", + "m4xshen/autoclose.nvim", + "stevearc/conform.nvim", + "mfussenegger/nvim-lint", + "neovim/nvim-lspconfig", + { - -- LSP Support - "neovim/nvim-lspconfig", - -- lsp download manager "williamboman/mason.nvim", - -- automatic lsp setup - "williamboman/mason-lspconfig.nvim", - -- additional formater support - "stevearc/conform.nvim", - -- additional linter support - "mfussenegger/nvim-lint", - -- mason autoinstaller for formatter's and linter's - "WhoIsSethDaniel/mason-tool-installer.nvim", - -- minimal snippet's support - "dcampos/nvim-snippy", - -- basic snippet's - "honza/vim-snippets", - -- cmp for autocompletion - { - "hrsh7th/nvim-cmp", - dependencies = { - -- cmp nvim-lsp plugin - "hrsh7th/cmp-nvim-lsp", - -- path comletion - "hrsh7th/cmp-path", - -- cmp snippy support - "dcampos/cmp-snippy", - "hrsh7th/cmp-calc", - }, - event = { "InsertEnter", "CmdlineEnter" }, + dependencies = { + "williamboman/mason-lspconfig.nvim", + -- for formatters and linters + "WhoIsSethDaniel/mason-tool-installer.nvim", }, - -- kind icons - "onsails/lspkind.nvim", - -- Minimal neovim modules for a lot of things - "echasnovski/mini.nvim", - -- Adds git related signs to the gutter, as well as utilities for managing changes - "lewis6991/gitsigns.nvim", - -- better ntrw - "tpope/vim-vinegar", - "tpope/vim-eunuch", - -- integration with tmux keybinds - { - "christoomey/vim-tmux-navigator", - cmd = { - "TmuxNavigateLeft", - "TmuxNavigateDown", - "TmuxNavigateUp", - "TmuxNavigateRight", - "TmuxNavigatePrevious", - }, - keys = { - { "", "TmuxNavigateLeft" }, - { "", "TmuxNavigateDown" }, - { "", "TmuxNavigateUp" }, - { "", "TmuxNavigateRight" }, - { "", "TmuxNavigatePrevious" }, - }, + config = function() + require("mason").setup({ + ui = { + border = "rounded", + }, + }) + end, + }, + { + --snippets + "L3MON4D3/LuaSnip", + version = "v2.*", + build = "make install_jsregexp", + }, + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-buffer", + "saadparwaiz1/cmp_luasnip", + "onsails/lspkind.nvim", }, - -- auto close brackets - "m4xshen/autoclose.nvim", + event = { "InsertEnter", "CmdlineEnter" }, }, + + { + "christoomey/vim-tmux-navigator", + cmd = { + "TmuxNavigateLeft", + "TmuxNavigateDown", + "TmuxNavigateUp", + "TmuxNavigateRight", + "TmuxNavigatePrevious", + }, + keys = { + { "", "TmuxNavigateLeft" }, + { "", "TmuxNavigateDown" }, + { "", "TmuxNavigateUp" }, + { "", "TmuxNavigateRight" }, + { "", "TmuxNavigatePrevious" }, + }, + }, + { "ray-x/go.nvim", dependencies = { -- optional packages @@ -91,9 +91,6 @@ require("lazy").setup({ build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries }, - "mg979/vim-visual-multi", - "jghauser/follow-md-links.nvim", - { "dstein64/vim-startuptime", cmd = "StartupTime", @@ -132,9 +129,8 @@ require("lazy").setup({ vim.cmd.colorscheme("nord") end, }, - - -- Fuzzy Finder (files, lsp, etc) { + -- Fuzzy Finder (files, lsp, etc) "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim", @@ -146,20 +142,14 @@ require("lazy").setup({ }, }, }, - { - -- Highlight, edit, and navigate code "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", }, - { - -- harpoon your way around code - { - "ThePrimeagen/harpoon", - branch = "harpoon2", - requires = { "nvim-lua/plenary.nvim", lazy = true }, - }, + "ThePrimeagen/harpoon", + branch = "harpoon2", + requires = { "nvim-lua/plenary.nvim", lazy = true }, }, }, { @@ -175,14 +165,13 @@ require("lazy").setup({ }, }, }, - install = { - colorscheme = { "nord" }, - missing = false, - }, - change_detection = { - enabled = false, - notify = false, - }, - checker = { enabled = false }, - -- defaults = {lazy = true}, + -- install = { + -- colorscheme = { "nord" }, + -- missing = false, + -- }, + -- change_detection = { + -- enabled = true, + -- notify = true, + -- }, + -- checker = { enabled = true, notify = false }, }) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 715d0f9..e94966a 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -14,8 +14,9 @@ map("n", " lq", vim.diagnostic.setqflist) -- [[ LSP Setups ]] local lspconfig = require("lspconfig") --- go lspconfig.gopls.setup({}) +lspconfig.clangd.setup({}) +lspconfig.emmet_ls.setup({}) -- lua -- with neovim support @@ -54,14 +55,19 @@ require("lspconfig").lua_ls.setup({ -- [[ nvim cmp ]] require("cmp_nvim_lsp").default_capabilities() local cmp = require("cmp") +local context = require("cmp.config.context") local lspkind = require("lspkind") cmp.setup({ - completion = { - autocomplete = false, - }, + enabled = function() + if context.in_treesitter_capture("comment") == true or context.in_syntax_group("Comment") then + return false + else + return true + end + end, snippet = { expand = function(args) - require("snippy").expand_snippet(args.body) + require("luasnip").lsp_expand(args.body) end, }, window = { @@ -86,11 +92,14 @@ cmp.setup({ }), }), sources = cmp.config.sources({ - { name = "nvim_lsp" }, - -- { name = "snippy" }, + { + name = "nvim_lsp", + keyword_length = 3, + }, + { name = "luasnip" }, }, { - { name = "buffer" }, - { name = "calc" }, + -- { name = "buffer", max_item_count = 5 }, + { name = "path", max_item_count = 5 }, }), formatting = { format = lspkind.cmp_format({ diff --git a/lua/config/map.lua b/lua/config/map.lua index 230588f..85c1e0f 100644 --- a/lua/config/map.lua +++ b/lua/config/map.lua @@ -25,7 +25,6 @@ map("x", "p", [["_dP]], { desc = "Paste while keeping the registry" }) -- moving map("i", "", "I", { noremap = true }) map("i", "", "A", { noremap = true }) -map("i", "", "D", { noremap = true }) -- buffers map("n", "sp", "sp", { desc = "Open horizontal split" }) @@ -53,18 +52,17 @@ map({ "n", "v" }, "d", [["_d]]) map("n", "rt", ":-1r " .. vim.fn.stdpath("config") .. "/templates", { noremap = true }) -- hide all -local s = { hidden_all = 0 } -map("n", "", function() - s.hidden_all = 1 - s.hidden_all - local opt = s.hidden_all == 0 - vim.opt.showmode = opt - vim.opt.ruler = opt - vim.opt.nu = opt - vim.opt.rnu = opt - vim.opt.showcmd = opt - vim.opt.laststatus = opt and 2 or 0 - vim.opt.signcolumn = opt and "yes" or "no" -end, { noremap = true }) +local hidden = true -- flag +vim.api.nvim_create_user_command("Hide", function() + hidden = hidden == false + vim.opt.showmode = hidden + vim.opt.ruler = hidden + vim.opt.nu = hidden + vim.opt.rnu = hidden + vim.opt.showcmd = hidden + vim.opt.laststatus = hidden and 2 or 0 + vim.opt.signcolumn = hidden and "yes" or "no" +end, {}) -- write map("n", "w", "write", { noremap = true }) diff --git a/lua/config/set.lua b/lua/config/set.lua index 3623a02..ce43d04 100644 --- a/lua/config/set.lua +++ b/lua/config/set.lua @@ -109,3 +109,6 @@ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.s vim.diagnostic.config({ float = { border = _border }, }) + +-- highlight to-do's +vim.cmd("match Todo /\\(TODO\\|FIXME\\):/") diff --git a/todo.md b/todo.md index a13c7a1..9f4deee 100644 --- a/todo.md +++ b/todo.md @@ -2,6 +2,8 @@ - [x] completion keybind - [x] go to definition - [ ] luasnip snippets +- [ ] gitsigns keybinds +- [ ] disable autoclose when in a comment ## cmp - [x] completion from only 4 characters @@ -10,3 +12,4 @@ - [ ] do not propose snippets in completion menu - change lsp settings for this? - [ ] look at the configuration options +- [ ] better looking completion menu -- cgit v1.2.3