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
hydra({
name = 'Side scroll',
name = "Side scroll",
config = {
{
position = 'bottom-right',
border = 'rounded',
position = "bottom-right",
border = "rounded",
},
},
mode = 'n',
body = 'z',
mode = "n",
body = "z",
heads = {
{ 'h', '5zh' },
{ 'l', '5zl', { desc = '←/→' } },
{ 'H', 'zH' },
{ 'L', 'zL', { desc = 'half screen ←/→' } },
{ "h", "5zh" },
{ "l", "5zl", { desc = "←/→" } },
{ "H", "zH" },
{ "L", "zL", { desc = "half screen ←/→" } },
},
})
-- Git Integration
local gitsigns = require('gitsigns')
local gitsigns = require("gitsigns")
local hint = [[
_J_: next hunk _s_: stage hunk _d_: show deleted _b_: blame line
@ -33,11 +33,11 @@ local hint = [[
hydra({
hint = hint,
config = {
color = 'pink',
color = "pink",
invoke_on_body = true,
hint = {
position = 'bottom-right',
border = 'rounded',
position = "bottom-right",
border = "rounded",
},
on_enter = function()
vim.bo.modifiable = false
@ -50,68 +50,103 @@ hydra({
gitsigns.toggle_deleted(false)
end,
},
mode = { 'n', 'x' },
body = '<leader>G',
mode = { "n", "x" },
body = "<leader>G",
heads = {
{
'J',
"J",
function()
if vim.wo.diff then
return ']c'
return "]c"
end
vim.schedule(function()
gitsigns.next_hunk()
end)
return '<Ignore>'
return "<Ignore>"
end,
{ expr = true },
},
{
'K',
"K",
function()
if vim.wo.diff then
return '[c'
return "[c"
end
vim.schedule(function()
gitsigns.prev_hunk()
end)
return '<Ignore>'
return "<Ignore>"
end,
{ expr = true },
},
{ 's', ':Gitsigns stage_hunk<CR>', { silent = true } },
{ 'u', gitsigns.undo_stage_hunk },
{ 'S', gitsigns.stage_buffer },
{ 'p', gitsigns.preview_hunk },
{ 'd', gitsigns.toggle_deleted, { nowait = true } },
{ 'b', gitsigns.blame_line },
{ "s", ":Gitsigns stage_hunk<CR>", { silent = true } },
{ "u", gitsigns.undo_stage_hunk },
{ "S", gitsigns.stage_buffer },
{ "p", gitsigns.preview_hunk },
{ "d", gitsigns.toggle_deleted, { nowait = true } },
{ "b", gitsigns.blame_line },
{
'B',
"B",
function()
gitsigns.blame_line({ full = true })
end,
},
{ '/', gitsigns.show, { exit = true } }, -- show the base of the file
{ '<Enter>', '<cmd>Neogit<CR>', { exit = true } },
{ 'q', nil, { exit = true, nowait = true } },
{ "/", gitsigns.show, { exit = true } }, -- show the base of the file
{ "<Enter>", "<cmd>Neogit<CR>", { exit = true } },
{ "q", nil, { exit = true, nowait = true } },
},
})
-- Hydra to repeat expanding windows
hydra({
name = 'Window Sizing',
mode = 'n',
body = '<C-w>',
name = "Window Sizing",
mode = "n",
body = "<C-w>",
config = {
{
position = 'bottom-right',
border = 'rounded',
position = "bottom-right",
border = "rounded",
},
},
heads = {
{ '<', '2<C-w><' },
{ '>', '2<C-w>>', { desc = '←/→' } },
{ '+', '2<C-w>+' },
{ '-', '2<C-w>-', { desc = '↑/↓' } },
{ "<", "2<C-w><" },
{ ">", "2<C-w>>", { desc = "←/→" } },
{ "+", "2<C-w>+" },
{ "-", "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 = {
"anuvyklack/keymap-layer.nvim",
"lewis6991/gitsigns.nvim",
"jbyuki/venn.nvim",
},
config = function()
require("plugins.configs.hydra")