Skip to content

Commit

Permalink
add mappings and sort stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed May 7, 2024
1 parent ede0e1a commit 5ae7d39
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 57 deletions.
1 change: 1 addition & 0 deletions .config/nvim/lua/plugins/functionality.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ local M = {
cmd = { 'BDelete', 'BWipeout' },
keys = {
{ '<leader>bd', '<cmd>BDelete this<cr>' },
{ '<leader>bh', '<cmd>BDelete hidden<cr>' },
},
init = function()
require('user.menu').add_actions(nil, {
Expand Down
109 changes: 56 additions & 53 deletions .config/nvim/lua/plugins/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,62 @@ return {
{ '<c-b>', ':FzfLua buffers<cr>', silent = true },
{ '<leader>hh', ':FzfLua help_tags<cr>', silent = true },
{ '<leader>i', ':FzfLua oldfiles<cr>', silent = true },
'<F4>',
'<leader>/',
{
'<F4>',
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,
},
{
'<leader>/',
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 {
Expand All @@ -24,56 +78,5 @@ return {
end
return { winopts = { height = h, width = 0.60, row = 0.40 } }
end)

vim.keymap.set('n', '<leader>/', 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', '<F4>', 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,
}
3 changes: 2 additions & 1 deletion .config/nvim/lua/plugins/hlslens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ return {
{ 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]] },
{ 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]] },
},
config = true,
event = 'CmdlineEnter',
opts = {},
}
4 changes: 3 additions & 1 deletion .config/nvim/lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/lua/plugins/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ M.config = function()

ins_left {
'diff',
symbols = { added = '', modified = '󰝤 ', removed = '' },
symbols = { added = '', modified = ' ', removed = '' },
cond = conditions.hide_in_width,
}

Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/lua/plugins/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local M = {

M.keys = {
{ '<leader>v', ':lua require("nvim-tree.api").tree.find_file { open = true, focus = true }<cr>' },
{ '<c-o>', ':lua require("nvim-tree.api").tree.toggle()<cr>' },
{ '<c-o>', ':lua require("nvim-tree.api").tree.toggle()<cr>', silent = true },
}
M.config = function()
local nvim_tree = require 'nvim-tree'
Expand Down
9 changes: 9 additions & 0 deletions .config/nvim/lua/plugins/yanky.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local M = {
'gbprod/yanky.nvim',
dependencies = { 'kkharji/sqlite.lua' },
cmd = { 'YankyRingHistory' },
keys = {
'yy',
{ 'p', '<Plug>(YankyPutAfter)', mode = { 'n', 'x' } },
{ 'P', '<Plug>(YankyPutBefore)', mode = { 'n', 'x' } },
{ '<c-n>', '<Plug>(YankyCycleForward)' },
{ '<c-m>', '<Plug>(YankyCycleBackward)' },
{ '<leader>y', '<Cmd>YankyRingHistory<cr>' },
},
opts = {
ring = {
Expand All @@ -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

0 comments on commit 5ae7d39

Please sign in to comment.