diff options
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/.config/nvim/lua/plugins/cmp.lua | 60 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/plugins/telescope.lua | 36 |
2 files changed, 61 insertions, 35 deletions
diff --git a/nvim/.config/nvim/lua/plugins/cmp.lua b/nvim/.config/nvim/lua/plugins/cmp.lua index 30a1a88..4a7e016 100644 --- a/nvim/.config/nvim/lua/plugins/cmp.lua +++ b/nvim/.config/nvim/lua/plugins/cmp.lua @@ -1,3 +1,20 @@ +local function i_map_with(name, call_fallback, ...) + local args = { ... } + return { + i = function(fallback) + if not require("cmp")[name](unpack(args)) then + call_fallback(fallback) + end + end, + } +end + +local function i_map(name, ...) + return i_map_with(name, function(fb) + fb() + end, ...) +end + ---@type LazySpec local cmp = { "hrsh7th/nvim-cmp", @@ -6,18 +23,11 @@ local cmp = { dependencies = { "hrsh7th/cmp-path", }, -} - -function cmp:opts(opts) - local mapping = require("cmp.config.mapping") - local context = require("cmp.config.context") - local default = require("cmp.config.default")() - - return vim.tbl_extend("keep", opts, { + opts = { enabled = function() - return default.enabled() and vim.api.nvim_get_mode()["mode"] == "c" - or not context.in_treesitter_capture("comment") - or not context.in_syntax_group("Comment") + return require("cmp.config.default")().enabled() and vim.api.nvim_get_mode()["mode"] == "c" + or not require("cmp.config.context").in_treesitter_capture("comment") + or not require("cmp.config.context").in_syntax_group("Comment") end, window = { completion = { @@ -36,17 +46,29 @@ function cmp:opts(opts) return vim_item end, }, - mapping = mapping.preset.insert({ - ["<C-d>"] = mapping.scroll_docs(4), - ["<C-u>"] = mapping.scroll_docs(-4), - ["<C-Space>"] = mapping.complete(), - ["<CR>"] = mapping.confirm({ select = false }), - }), + mapping = { + ["<C-p>"] = i_map_with("select_prev_item", function(fallback) + local release = require("cmp").core:suspend() + fallback() + vim.schedule(release) + end), + ["<C-n>"] = i_map_with("select_next_item", function(fallback) + local release = require("cmp").core:suspend() + fallback() + vim.schedule(release) + end), + ["<C-d>"] = i_map("scroll_docs", 4), + ["<C-u>"] = i_map("scroll_docs", -4), + ["<C-Space>"] = i_map("complete", {}), + ["<CR>"] = i_map("confirm"), + ["<C-y>"] = i_map("confirm", { select = false }), + ["<C-e>"] = i_map("abort"), + }, sources = { { name = "path" }, }, - }) -end + }, +} ---@type LazySpec local cmp_nvim_lsp = { diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua index ff4fd5e..4d7c66f 100644 --- a/nvim/.config/nvim/lua/plugins/telescope.lua +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -2,6 +2,9 @@ local telescope = { "nvim-telescope/telescope.nvim", cmd = "Telescope", + dependencies = { + { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, + }, opts = { defaults = { borderchars = { "─", "│", "─", "│", "┌", "┐", "┘", "└" }, @@ -23,7 +26,6 @@ local telescope = { mappings = { i = { ["<Esc>"] = "close", - ["<C-h>"] = "which_key", ["<C-Down>"] = "cycle_history_next", ["<C-Up>"] = "cycle_history_prev", }, @@ -55,15 +57,6 @@ local telescope = { }, }, }, - extensions = { - live_grep_args = { - theme = "ivy", - }, - }, - }, - keys = { - "<leader>f", - "<leader>g", }, } @@ -89,9 +82,24 @@ function telescope:init() vim.keymap.set("n", "<leader>gt", builtin("git_status"), { desc = "status" }) end +function telescope:config(opts) + require("telescope").setup(opts) + require("telescope").load_extension("fzf") +end + ---@type LazySpec local telescope_live_grep_args = { "nvim-telescope/telescope-live-grep-args.nvim", + specs = { + "nvim-telescope/telescope.nvim", + opts = { + extensions = { + live_grep_args = { + theme = "ivy", + }, + }, + }, + }, } function telescope_live_grep_args:init() @@ -126,13 +134,9 @@ end ---@type LazySpec local M = { "nvim-lua/plenary.nvim", - { - "nvim-telescope/telescope-fzf-native.nvim", - build = "make", - }, - telescope_undo, - telescope_live_grep_args, telescope, + telescope_live_grep_args, + telescope_undo, } return M |