feat(nvim): add hydra for fancy diagrams

This commit is contained in:
Price Hiller 2022-09-05 07:12:26 -05:00
parent 6bd390a24c
commit 63bf0fc759
2 changed files with 78 additions and 41 deletions

View File

@ -1,26 +1,26 @@
local hydra = require('hydra') local hydra = require("hydra")
-- Side Scroll -- Side Scroll
hydra({ hydra({
name = 'Side scroll', name = "Side scroll",
config = { config = {
{ {
position = 'bottom-right', position = "bottom-right",
border = 'rounded', border = "rounded",
}, },
}, },
mode = 'n', mode = "n",
body = 'z', body = "z",
heads = { heads = {
{ 'h', '5zh' }, { "h", "5zh" },
{ 'l', '5zl', { desc = '←/→' } }, { "l", "5zl", { desc = "←/→" } },
{ 'H', 'zH' }, { "H", "zH" },
{ 'L', 'zL', { desc = 'half screen ←/→' } }, { "L", "zL", { desc = "half screen ←/→" } },
}, },
}) })
-- Git Integration -- Git Integration
local gitsigns = require('gitsigns') local gitsigns = require("gitsigns")
local hint = [[ local hint = [[
_J_: next hunk _s_: stage hunk _d_: show deleted _b_: blame line _J_: next hunk _s_: stage hunk _d_: show deleted _b_: blame line
@ -33,11 +33,11 @@ local hint = [[
hydra({ hydra({
hint = hint, hint = hint,
config = { config = {
color = 'pink', color = "pink",
invoke_on_body = true, invoke_on_body = true,
hint = { hint = {
position = 'bottom-right', position = "bottom-right",
border = 'rounded', border = "rounded",
}, },
on_enter = function() on_enter = function()
vim.bo.modifiable = false vim.bo.modifiable = false
@ -50,68 +50,103 @@ hydra({
gitsigns.toggle_deleted(false) gitsigns.toggle_deleted(false)
end, end,
}, },
mode = { 'n', 'x' }, mode = { "n", "x" },
body = '<leader>G', body = "<leader>G",
heads = { heads = {
{ {
'J', "J",
function() function()
if vim.wo.diff then if vim.wo.diff then
return ']c' return "]c"
end end
vim.schedule(function() vim.schedule(function()
gitsigns.next_hunk() gitsigns.next_hunk()
end) end)
return '<Ignore>' return "<Ignore>"
end, end,
{ expr = true }, { expr = true },
}, },
{ {
'K', "K",
function() function()
if vim.wo.diff then if vim.wo.diff then
return '[c' return "[c"
end end
vim.schedule(function() vim.schedule(function()
gitsigns.prev_hunk() gitsigns.prev_hunk()
end) end)
return '<Ignore>' return "<Ignore>"
end, end,
{ expr = true }, { expr = true },
}, },
{ 's', ':Gitsigns stage_hunk<CR>', { silent = true } }, { "s", ":Gitsigns stage_hunk<CR>", { silent = true } },
{ 'u', gitsigns.undo_stage_hunk }, { "u", gitsigns.undo_stage_hunk },
{ 'S', gitsigns.stage_buffer }, { "S", gitsigns.stage_buffer },
{ 'p', gitsigns.preview_hunk }, { "p", gitsigns.preview_hunk },
{ 'd', gitsigns.toggle_deleted, { nowait = true } }, { "d", gitsigns.toggle_deleted, { nowait = true } },
{ 'b', gitsigns.blame_line }, { "b", gitsigns.blame_line },
{ {
'B', "B",
function() function()
gitsigns.blame_line({ full = true }) gitsigns.blame_line({ full = true })
end, end,
}, },
{ '/', gitsigns.show, { exit = true } }, -- show the base of the file { "/", gitsigns.show, { exit = true } }, -- show the base of the file
{ '<Enter>', '<cmd>Neogit<CR>', { exit = true } }, { "<Enter>", "<cmd>Neogit<CR>", { exit = true } },
{ 'q', nil, { exit = true, nowait = true } }, { "q", nil, { exit = true, nowait = true } },
}, },
}) })
-- Hydra to repeat expanding windows -- Hydra to repeat expanding windows
hydra({ hydra({
name = 'Window Sizing', name = "Window Sizing",
mode = 'n', mode = "n",
body = '<C-w>', body = "<C-w>",
config = { config = {
{ {
position = 'bottom-right', position = "bottom-right",
border = 'rounded', border = "rounded",
}, },
}, },
heads = { heads = {
{ '<', '2<C-w><' }, { "<", "2<C-w><" },
{ '>', '2<C-w>>', { desc = '←/→' } }, { ">", "2<C-w>>", { desc = "←/→" } },
{ '+', '2<C-w>+' }, { "+", "2<C-w>+" },
{ '-', '2<C-w>-', { desc = '↑/↓' } }, { "-", "2<C-w>-", { desc = "↑/↓" } },
},
})
-- Hydra for diagrams
local hint = [[
Arrow^^^^^^ Select region with <C-v>
^ ^ _K_ ^ ^ _f_: surround it with box
_H_ ^ ^ _L_
^ ^ _J_ ^ ^ _<Esc>_
]]
hydra({
name = "Draw Diagram",
hint = hint,
config = {
color = "pink",
invoke_on_body = true,
hint = {
border = "rounded",
},
on_enter = function()
vim.o.virtualedit = "all"
vim.o.cursorline = true
vim.o.cursorcolumn = true
end,
},
mode = "n",
body = "<leader>D",
heads = {
{ "H", "<C-v>h:VBox<CR>" },
{ "J", "<C-v>j:VBox<CR>" },
{ "K", "<C-v>k:VBox<CR>" },
{ "L", "<C-v>l:VBox<CR>" },
{ "f", ":VBox<CR>", { mode = "v" } },
{ "<Esc>", nil, { exit = true } },
}, },
}) })

View File

@ -738,6 +738,8 @@ return packer.startup({
requires = { requires = {
"anuvyklack/keymap-layer.nvim", "anuvyklack/keymap-layer.nvim",
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
"jbyuki/venn.nvim",
}, },
config = function() config = function()
require("plugins.configs.hydra") require("plugins.configs.hydra")