From 5ae7d391f3e9b371095d5fb4661946ce8633c336 Mon Sep 17 00:00:00 2001 From: Moshe Avni Date: Tue, 7 May 2024 11:14:08 +0300 Subject: [PATCH] add mappings and sort stuff --- .config/nvim/lua/plugins/functionality.lua | 1 + .config/nvim/lua/plugins/fzf.lua | 109 +++++++++++---------- .config/nvim/lua/plugins/hlslens.lua | 3 +- .config/nvim/lua/plugins/init.lua | 4 +- .config/nvim/lua/plugins/lualine.lua | 2 +- .config/nvim/lua/plugins/tree.lua | 2 +- .config/nvim/lua/plugins/yanky.lua | 9 ++ 7 files changed, 73 insertions(+), 57 deletions(-) diff --git a/.config/nvim/lua/plugins/functionality.lua b/.config/nvim/lua/plugins/functionality.lua index 6feeab44..a0eb621f 100644 --- a/.config/nvim/lua/plugins/functionality.lua +++ b/.config/nvim/lua/plugins/functionality.lua @@ -115,6 +115,7 @@ local M = { cmd = { 'BDelete', 'BWipeout' }, keys = { { 'bd', 'BDelete this' }, + { 'bh', 'BDelete hidden' }, }, init = function() require('user.menu').add_actions(nil, { diff --git a/.config/nvim/lua/plugins/fzf.lua b/.config/nvim/lua/plugins/fzf.lua index 7a2fa7b4..f3e298b1 100644 --- a/.config/nvim/lua/plugins/fzf.lua +++ b/.config/nvim/lua/plugins/fzf.lua @@ -5,8 +5,62 @@ return { { '', ':FzfLua buffers', silent = true }, { 'hh', ':FzfLua help_tags', silent = true }, { 'i', ':FzfLua oldfiles', silent = true }, - '', - '/', + { + '', + function() + require('fzf-lua').git_branches { + actions = { + ['ctrl-r'] = function(selected) + vim.ui.input({ prompt = 'Rename branch: ', default = selected[1] }, function(new_name) + if new_name == '' then + require('fzf-lua.utils').warn 'Action aborted' + return + end + -- Rename the branch + local toplevel = vim.trim(vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait().stdout) + local _, ret, stderr = require('user.utils').get_os_command_output({ 'git', 'branch', '-m', selected[1], new_name }, toplevel) + if ret == 0 then + require('fzf-lua.utils').info('Renamed branch ' .. selected[1] .. ' to ' .. new_name) + return + else + local msg = string.format('Error when renaming branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) + require('fzf-lua.utils').err(msg) + end + end) + end, + ['ctrl-d'] = function(selected) + vim.ui.select({ 'Yes', 'No' }, { prompt = 'Are you sure you want to delete the branch ' .. selected[1] }, function(yes_or_no) + if yes_or_no == 'No' then + require('fzf-lua.utils').warn 'Action aborted' + return + end + -- Delete the branch + local toplevel = vim.trim(vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait().stdout) + local _, ret, stderr = require('user.utils').get_os_command_output({ 'git', 'branch', '-D', selected[1] }, toplevel) + if ret == 0 then + require('fzf-lua.utils').info('Deleted branch ' .. selected[1]) + return + else + local msg = string.format('Error when deleting branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) + require('fzf-lua.utils').err(msg) + end + end) + end, + }, + cmd = [=[git for-each-ref --sort=-committerdate --format="%(refname:short)" | grep -n . | sed "s?origin/??g" | sort -t: -k2 -u | sort -n | cut -d: -f2]=], + } + end, + }, + { + '/', + function() + require('fzf-lua').live_grep { + keymap = { fzf = { ['ctrl-q'] = 'select-all+accept' } }, + multiprocess = true, + rg_opts = [=[--column --line-number --hidden --no-heading --color=always --smart-case --max-columns=4096 -g '!.git' -e]=], + } + end, + }, }, config = function() require('fzf-lua').setup { @@ -24,56 +78,5 @@ return { end return { winopts = { height = h, width = 0.60, row = 0.40 } } end) - - vim.keymap.set('n', '/', function() - require('fzf-lua').live_grep { - keymap = { fzf = { ['ctrl-q'] = 'select-all+accept' } }, - multiprocess = true, - rg_opts = [=[--column --line-number --hidden --no-heading --color=always --smart-case --max-columns=4096 -g '!.git' -e]=], - } - end) - vim.keymap.set('n', '', function() - require('fzf-lua').git_branches { - actions = { - ['ctrl-r'] = function(selected) - vim.ui.input({ prompt = 'Rename branch: ', default = selected[1] }, function(new_name) - if new_name == '' then - require('fzf-lua.utils').warn 'Action aborted' - return - end - -- Rename the branch - local toplevel = vim.trim(vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait().stdout) - local _, ret, stderr = require('user.utils').get_os_command_output({ 'git', 'branch', '-m', selected[1], new_name }, toplevel) - if ret == 0 then - require('fzf-lua.utils').info('Renamed branch ' .. selected[1] .. ' to ' .. new_name) - return - else - local msg = string.format('Error when renaming branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) - require('fzf-lua.utils').err(msg) - end - end) - end, - ['ctrl-d'] = function(selected) - vim.ui.select({ 'Yes', 'No' }, { prompt = 'Are you sure you want to delete the branch ' .. selected[1] }, function(yes_or_no) - if yes_or_no == 'No' then - require('fzf-lua.utils').warn 'Action aborted' - return - end - -- Delete the branch - local toplevel = vim.trim(vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait().stdout) - local _, ret, stderr = require('user.utils').get_os_command_output({ 'git', 'branch', '-D', selected[1] }, toplevel) - if ret == 0 then - require('fzf-lua.utils').info('Deleted branch ' .. selected[1]) - return - else - local msg = string.format('Error when deleting branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) - require('fzf-lua.utils').err(msg) - end - end) - end, - }, - cmd = [=[git for-each-ref --sort=-committerdate --format="%(refname:short)" | grep -n . | sed "s?origin/??g" | sort -t: -k2 -u | sort -n | cut -d: -f2]=], - } - end) end, } diff --git a/.config/nvim/lua/plugins/hlslens.lua b/.config/nvim/lua/plugins/hlslens.lua index abebf442..21193ea7 100644 --- a/.config/nvim/lua/plugins/hlslens.lua +++ b/.config/nvim/lua/plugins/hlslens.lua @@ -8,5 +8,6 @@ return { { 'g*', [[g*lua require('hlslens').start()]] }, { 'g#', [[g#lua require('hlslens').start()]] }, }, - config = true, + event = 'CmdlineEnter', + opts = {}, } diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index d82f24a6..45c20835 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -105,8 +105,10 @@ local M = { event = 'VeryLazy', }, { - 'tpope/vim-surround', + 'kylechui/nvim-surround', + version = '*', -- Use for stability; omit to use `main` branch for the latest features keys = { 'ds', 'cs', 'ys', { 'S', nil, mode = 'v' } }, + opts = {}, }, { 'JoosepAlviste/nvim-ts-context-commentstring', diff --git a/.config/nvim/lua/plugins/lualine.lua b/.config/nvim/lua/plugins/lualine.lua index f57020ec..2160816b 100644 --- a/.config/nvim/lua/plugins/lualine.lua +++ b/.config/nvim/lua/plugins/lualine.lua @@ -182,7 +182,7 @@ M.config = function() ins_left { 'diff', - symbols = { added = ' ', modified = '󰝤 ', removed = ' ' }, + symbols = { added = ' ', modified = ' ', removed = ' ' }, cond = conditions.hide_in_width, } diff --git a/.config/nvim/lua/plugins/tree.lua b/.config/nvim/lua/plugins/tree.lua index c929561b..ca196e91 100644 --- a/.config/nvim/lua/plugins/tree.lua +++ b/.config/nvim/lua/plugins/tree.lua @@ -51,7 +51,7 @@ local M = { M.keys = { { 'v', ':lua require("nvim-tree.api").tree.find_file { open = true, focus = true }' }, - { '', ':lua require("nvim-tree.api").tree.toggle()' }, + { '', ':lua require("nvim-tree.api").tree.toggle()', silent = true }, } M.config = function() local nvim_tree = require 'nvim-tree' diff --git a/.config/nvim/lua/plugins/yanky.lua b/.config/nvim/lua/plugins/yanky.lua index 6097f09d..a11e9610 100644 --- a/.config/nvim/lua/plugins/yanky.lua +++ b/.config/nvim/lua/plugins/yanky.lua @@ -1,12 +1,14 @@ local M = { 'gbprod/yanky.nvim', dependencies = { 'kkharji/sqlite.lua' }, + cmd = { 'YankyRingHistory' }, keys = { 'yy', { 'p', '(YankyPutAfter)', mode = { 'n', 'x' } }, { 'P', '(YankyPutBefore)', mode = { 'n', 'x' } }, { '', '(YankyCycleForward)' }, { '', '(YankyCycleBackward)' }, + { 'y', 'YankyRingHistory' }, }, opts = { ring = { @@ -16,6 +18,13 @@ local M = { cancel_event = 'update', }, }, + init = function() + require('user.menu').add_actions('Yanky',{ + ['Yank history'] = function() + vim.cmd('YankyRingHistory') + end + }) + end, } return M