From 12d499f3ab3e786bc2e81221f0d981ed241f4f93 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 28 Jul 2024 22:59:53 +0200 Subject: [PATCH] Add snippet bindings & setup omnifunc opts --- modules/cli/nvim/lua/plugins/cmp.lua | 5 +- modules/cli/nvim/lua/settings.lua | 83 ++++++++++++++++++---------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/modules/cli/nvim/lua/plugins/cmp.lua b/modules/cli/nvim/lua/plugins/cmp.lua index 5e1d563..c3a7135 100644 --- a/modules/cli/nvim/lua/plugins/cmp.lua +++ b/modules/cli/nvim/lua/plugins/cmp.lua @@ -24,6 +24,7 @@ return { [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ @@ -61,9 +62,5 @@ return { }, } end, - init = function() - vim.opt.completeopt = { "menuone", "preview", } - vim.opt.pumheight = 15 - end }, } diff --git a/modules/cli/nvim/lua/settings.lua b/modules/cli/nvim/lua/settings.lua index 5f4d281..3e5ed07 100644 --- a/modules/cli/nvim/lua/settings.lua +++ b/modules/cli/nvim/lua/settings.lua @@ -48,8 +48,16 @@ local options = { foldsep = " ", foldclose = "", }, + + completeopt = { "menuone", "popup", "noinsert", "fuzzy" }, + pumheight = 15, } +vim.g.loaded_python3_provider = 0 +vim.g.loaded_ruby_provider = 0 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_node_provider = 0 + for k, v in pairs(options) do vim.opt[k] = v end @@ -61,52 +69,69 @@ vim.cmd("autocmd BufEnter * setlocal formatoptions-=ro") vim.g.mapleader = " " vim.g.maplocalleader = " " -local function keymap(mode, l, r, desc) - vim.keymap.set(mode, l, r, { noremap = true, silent = true, desc = desc }) -end - - -- Stay in indent mode -keymap("v", "<", "", ">gv") +vim.keymap.set("v", "<", "", ">gv") -- Move in insert mode -- -keymap("i", "", "") -keymap("i", "", "") -keymap("i", "", "") -keymap("i", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") -keymap("i", "", "") -keymap("c", "", "") -keymap("i", "", "") -- Keymap for CTRL-BACKSPACE on some termial emulators. -keymap("c", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("c", "", "") +-- vim.keymap.set("i", "", "") -- Keymap for CTRL-BACKSPACE on some termial emulators. +-- vim.keymap.set("c", "", "") -- Center screen when navigating search results -keymap("n", "n", "nzz") -keymap("n", "N", "Nzz") +vim.keymap.set("n", "n", "nzzzv", { desc = "Next result" }) +vim.keymap.set("n", "N", "Nzzzv", { desc = "Previous result" }) -keymap({ "n", "x" }, "y", '"+y', "Yank to system clipboard") -keymap({ "n", "x" }, "Y", '"+y$', "Yank line to system clipboard") +vim.keymap.set({ "n", "x" }, "y", '"+y', { desc = "Yank to system clipboard" }) +vim.keymap.set({ "n", "x" }, "Y", '"+y$', { desc = "Yank line to system clipboard" }) -keymap({ "n", "x" }, "p", '"+p', "Past from system clipboard") -keymap({ "n", "x" }, "P", '"+P', "Past line from system clipboard") +vim.keymap.set({ "n", "x" }, "p", '"+p', { desc = "Past from system clipboard" }) +vim.keymap.set({ "n", "x" }, "P", '"+P', { desc = "Past line from system clipboard" }) -keymap("n", "", "cnextzz", "Next quickfix") -keymap("n", "", "cprevzz", "Prev quickfix") -keymap("n", "q", "cclose", "Close quickfix") +vim.keymap.set("n", "", "cnextzz", { desc = "Next quickfix" }) +vim.keymap.set("n", "", "cprevzz", { desc = "Prev quickfix" }) +vim.keymap.set("n", "q", "cclose", { desc = "Close quickfix" }) +vim.keymap.set('n', '[q', 'cprevzvzz', { desc = 'Previous quickfix item' }) +vim.keymap.set('n', ']q', 'cnextzvzz', { desc = 'Next quickfix item' }) +vim.keymap.set('n', '[l', 'lprevzvzz', { desc = 'Previous loclist item' }) +vim.keymap.set('n', ']l', 'lnextzvzz', { desc = 'Next loclist item' }) -keymap("t", "", "", "+windows") -keymap("t", "", "", "Normal mode") + +vim.keymap.set("t", "", "", { desc = "+windows" }) +vim.keymap.set("t", "", "", { desc = "Normal mode" }) vim.keymap.set({ "n", "x" }, "gq", "gw", { desc = "Reformat using textwidth (tw)", noremap = true }) -vim.keymap.set("n", "", "lua vim.snippet.stop()", { noremap = true }) + +-- Clear snippets with C-l and go to next/prev with C-n & C-p +vim.keymap.set("n", "", function() + if vim.snippet then + vim.snippet.stop() + end + return "" +end, { expr = true }) +vim.keymap.set({ "i", "s" }, "", function() + if vim.snippet.active({ direction = 1 }) then + vim.snippet.jump(1) + end +end) +vim.keymap.set({ "i", "s" }, "", function() + if vim.snippet.active({ direction = -1 }) then + vim.snippet.jump(-1) + end +end) vim.cmd("autocmd FileType qf setl nolist") vim.cmd("syntax on") vim.api.nvim_create_autocmd('TextYankPost', { - group = vim.api.nvim_create_augroup("HighlightYank", {}), - pattern = '*', + group = vim.api.nvim_create_augroup("HighlightYank", { clear = true }), + desc = "highlight on yank", callback = function() vim.highlight.on_yank({ higroup = 'Visual',