From 49b0f23821690ac4b58aa4edf5f4608b43f1e8bf Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 21 Aug 2023 19:27:20 +0300 Subject: nvim: change cutlass suite and fix telescope + cmp issues --- .config/nvim/lua/plugins/cmp.lua | 56 ++++++++++++++++++++++--- .config/nvim/lua/plugins/cutlass.lua | 75 +++++++++++++++++++++++++--------- .config/nvim/lua/plugins/telescope.lua | 32 +++++++++------ 3 files changed, 127 insertions(+), 36 deletions(-) (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 78ff9a9..828d7c2 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -1,4 +1,3 @@ --- autocompletion return { { "hrsh7th/nvim-cmp", @@ -46,18 +45,35 @@ return { TypeParameter = "", } + ---@diagnostic disable-next-line: missing-fields cmp.setup({ - enabled = true, + enabled = function() + -- disable autocompletion in prompt + local buftype = vim.api.nvim_buf_get_option(0, "buftype") + if buftype == "prompt" then return false end + + local context = require 'cmp.config.context' + -- disable autocompletion in comments + return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") + end, + ---@diagnostic disable-next-line: missing-fields + completion = { + completeopt = "menu,menuone,noselect", + }, + window = { + documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered(), + }, snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false, @@ -81,6 +97,7 @@ return { end end, { "i", "s" }), }), + ---@diagnostic disable-next-line: missing-fields formatting = { fields = { "kind", "abbr", "menu" }, format = function(entry, vim_item) @@ -103,12 +120,41 @@ return { }, }) - -- If you want insert `(` after select function or method item + -- insert `(` after select function or method item local cmp_autopairs = require('nvim-autopairs.completion.cmp') cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done() ) + + ---@diagnostic disable-next-line: missing-fields + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, + }, { + { name = 'buffer' }, + }) + }) + + -- use buffer source for `/` . + ---@diagnostic disable-next-line: missing-fields + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + -- use cmdline & path source for ':' . + ---@diagnostic disable-next-line: missing-fields + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) end, }, } diff --git a/.config/nvim/lua/plugins/cutlass.lua b/.config/nvim/lua/plugins/cutlass.lua index 0b8ef52..b9332a9 100644 --- a/.config/nvim/lua/plugins/cutlass.lua +++ b/.config/nvim/lua/plugins/cutlass.lua @@ -3,26 +3,36 @@ return { 'svermeulen/vim-cutlass', }, { - 'svermeulen/vim-subversive', + 'gbprod/substitute.nvim', config = function() local map = require("helpers.keys").map - -- substitute from yank - map('n', 'ys', '(SubversiveSubstitute)', "substitute from yank") - map('n', 'yss', '(SubversiveSubstituteLine)', "substitute from yank, line") - map('n', 'yS', '(SubversiveSubstituteToEndOfLine)', "substitute from yank, eol") + map("n", "s", require('substitute').operator, "substitute") + map("n", "ss", require('substitute').line, "substitute: linewise") + map("n", "S", require('substitute').eol, "substitute: eol") + map("x", "s", require('substitute').visual, "substitute: visual") - -- substitute over range - map( { 'n', 'x' }, 's', '(SubversiveSubstituteRange)', "start substitude over range") - map('n', 'ss', '(SubversiveSubstituteWordRange)', "start substitude over range") - end + map("n", "s", require('substitute.range').operator, "substitute: over range") + map("x", "s", require('substitute.range').visual, "substitute: over visual") + map("n", "ss", require('substitute.range').word, "substitute: with word over range") + + map("n", "sx", require('substitute.exchange').operator, "exchange") + map("n", "sxx", require('substitute.exchange').line, "exchange line") + map("x", "sX", require('substitute.exchange').visual, "exchange visual") + map("n", "sxc", require('substitute.exchange').cancel, "exchange cancel") + + require("substitute").setup({ + highlight_substituted_text = { + enabled = true, + timer = 300, + }, + }) + end, }, { - 'svermeulen/vim-yoink', + "gbprod/yanky.nvim", config = function() - vim.g.yoinkIncludeDeleteOperations = 1 - - -- fix the Target STRING not available + -- fix Target STRING not available vim.g.clipboard = { name = 'xsel_override', copy = { @@ -38,14 +48,41 @@ return { local map = require("helpers.keys").map - -- yoink paste - map('n', 'p', '(YoinkPaste_p)') - map('n', 'P', '(YoinkPaste_P)') + map({ "n", "x" }, 'p', '(YankyPutAfter)') + map({ "n", "x" }, 'P', '(YankyPutBefore)') + + map("n", "", "(YankyCycleForward)") + map("n", "", "(YankyCycleBackward)") - -- iterate over yank list - map('n', '', '(YoinkPostPasteSwapBack)') - map('n', '', '(YoinkPostPasteSwapForward)') + local utils = require("yanky.utils") + local mapping = require("yanky.telescope.mapping") + + require("yanky").setup({ + ring = { + history_length = 100, + storage = "shada", + sync_with_numbered_registers = true, + cancel_event = "update", + ignore_registers = { "_" }, + }, + system_clipboard = { + sync_with_ring = true, + }, + picker = { + telescope = { + use_default_mappings = false, + mappings = { + default = mapping.set_register(utils.get_default_register()), + }, + }, + }, + highlight = { + on_put = true, + on_yank = true, + timer = 300, + }, + }) end, } } diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index ecea32b..be6fdd7 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -1,6 +1,7 @@ return { { "nvim-telescope/telescope.nvim", + priority = 500, dependencies = { "nvim-lua/plenary.nvim", { @@ -8,38 +9,45 @@ return { build = "make", cond = vim.fn.executable("make") == 1 }, + "gbprod/yanky.nvim", }, + lazy = false, config = function() require('telescope').setup({ + defaults = { + path_display = { "truncate" }, + }, extensions = { fzf = { - fuzzy = true, -- false will only do exact matching + fuzzy = true, -- false will only do exact matching override_generic_sorter = true, override_file_sorter = true, case_mode = "smart_case", - } - } + }, + }, }) -- Enable telescope fzf native, if installed pcall(require("telescope").load_extension, "fzf") local map = require("helpers.keys").map - map("n", "fr", require("telescope.builtin").oldfiles, "recently opened") - map("n", "", require("telescope.builtin").buffers, "open buffers") + map("n", "fr", require("telescope.builtin").oldfiles, "🔭: recently opened") + map("n", "", require("telescope.builtin").buffers, "🔭: open buffers") map("n", "/", function() - -- You can pass additional configuration to telescope to change theme, layout, etc. + -- you can pass additional configuration to telescope to change theme, layout, etc. require("telescope.builtin").current_buffer_fuzzy_find(require("telescope.themes").get_dropdown({ winblend = 10, previewer = false, })) - end, "search in current buffer") + end, "🔭: search in current buffer") - map("n", "sf", require("telescope.builtin").find_files, "files") - map("n", "sh", require("telescope.builtin").help_tags, "help") - map("n", "sw", require("telescope.builtin").grep_string, "current word") - map("n", "sg", require("telescope.builtin").live_grep, "grep") - map("n", "sd", require("telescope.builtin").diagnostics, "diagnostics") + map("n", "sf", require("telescope.builtin").find_files, "🔭: find files") + map("n", "sh", require("telescope.builtin").help_tags, "🔭: help") + map("n", "sw", require("telescope.builtin").grep_string, "🔭: current word") + map("n", "sg", require("telescope.builtin").live_grep, "🔭: live grep") + map("n", "sd", require("telescope.builtin").diagnostics, "🔭: diagnostics") + require("telescope").load_extension("yank_history") + map("n", "sp", require("telescope").extensions.yank_history.yank_history, "🔭: yank history") end, }, } -- cgit v1.2.3-70-g09d2