Files
AstroVim_Config/lua/plugins/motion.lua

135 lines
4.8 KiB
Lua

-- Plugins related to motion
return {
-- Faster change/delete/replace delimiter pairs
{
"echasnovski/mini.surround",
opts = { n_lines = 200 },
keys = {
{ "sa", mode = { "n", "x" }, desc = "Add surrounding" },
{ "sd", mode = { "n", "x" }, desc = "Delete surrounding" },
{ "sr", mode = { "n", "x" }, desc = "Replace surrounding" },
{ "sf", mode = { "n", "x" }, desc = "Find right surrounding" },
{ "sF", mode = { "n", "x" }, desc = "Find left surrounding" },
{ "sh", mode = { "n", "x" }, desc = "Highlight surrounding" },
{ "sn", mode = { "n", "x" }, desc = "Update `MiniSurround.config.n_lines`" },
},
},
-- Brackets splitjoin
{
"Wansmer/treesj",
cmd = { "TSJToggle", "TSJSplit", "TSJJoin" },
opts = {
use_default_keymaps = false,
max_join_length = 150,
},
keys = {
{ "gs", "<Cmd>TSJToggle<CR>", mode = { "n" }, desc = "Toggle splitjoin" },
},
},
-- {
-- "echasnovski/mini.ai",
-- event = "User AstroFile",
-- opts = function()
-- -- Register to which-key
-- local i = {
-- [" "] = "Whitespace",
-- ["?"] = "User Prompt",
-- _ = "Underscore",
-- a = "Argument",
-- b = "Paired ), ], }",
-- c = "Class",
-- d = "Digit(s)",
-- e = "Word in CamelCase & snake_case",
-- f = "Function",
-- g = "Entire file",
-- o = "Block, conditional, loop",
-- q = "Quote `, \", '",
-- t = "Tag",
-- u = "Use/call function & method",
-- U = "Use/call without dot in name",
-- }
-- local a = vim.deepcopy(i)
-- for k, v in pairs(a) do
-- a[k] = v:gsub(" including.*", "")
-- end
-- local ic = vim.deepcopy(i)
-- local ac = vim.deepcopy(a)
-- for key, name in pairs { n = "Next", l = "Last" } do
-- i[key] = vim.tbl_extend("force", { name = "Inside " .. name .. " textobject" }, ic)
-- a[key] = vim.tbl_extend("force", { name = "Around " .. name .. " textobject" }, ac)
-- end
-- require("which-key").register {
-- mode = { "o", "x" },
-- i = i,
-- a = a,
-- }
-- -- define custom textobjects
-- local ai = require "mini.ai"
-- return {
-- n_lines = 500,
-- custom_textobjects = {
-- o = ai.gen_spec.treesitter { -- code block
-- a = { "@block.outer", "@conditional.outer", "@loop.outer" },
-- i = { "@block.inner", "@conditional.inner", "@loop.inner" },
-- },
-- f = ai.gen_spec.treesitter { a = "@function.outer", i = "@function.inner" }, -- function
-- c = ai.gen_spec.treesitter { a = "@class.outer", i = "@class.inner" }, -- class
-- t = { "<([%p%w]-)%f[^<%w][^<>]->.-</%1>", "^<.->().*()</[^/]->$" }, -- tags
-- d = { "%f[%d]%d+" }, -- digits
-- e = { -- Word with case
-- { "%u[%l%d]+%f[^%l%d]", "%f[%S][%l%d]+%f[^%l%d]", "%f[%P][%l%d]+%f[^%l%d]", "^[%l%d]+%f[^%l%d]" },
-- "^().*()$",
-- },
-- u = ai.gen_spec.function_call(), -- u for "Usage"
-- U = ai.gen_spec.function_call { name_pattern = "[%w_]" }, -- without dot in function name
-- },
-- }
-- end,
-- },
-- Better move by word
{
"chrisgrieser/nvim-spider",
opts = {},
keys = {
{ "w", "<Cmd>lua require('spider').motion('w')<CR>", mode = { "n", "o", "x" }, desc = "Spider-w" },
{ "e", "<Cmd>lua require('spider').motion('e')<CR>", mode = { "n", "o", "x" }, desc = "Spider-e" },
{ "b", "<Cmd>lua require('spider').motion('b')<CR>", mode = { "n", "o", "x" }, desc = "Spider-b" },
{ "ge", "<Cmd>lua require('spider').motion('ge')<CR>", mode = { "n", "o", "x" }, desc = "Spider-ge" },
},
},
-- Duplicate line/block up/down
{
"hinell/duplicate.nvim",
keys = {
{ "<A-K>", "<Cmd>LineDuplicate -1<CR>", mode = { "n" }, desc = "Duplicate line up" },
{ "<A-J>", "<Cmd>LineDuplicate +1<CR>", mode = { "n" }, desc = "Duplicate line down" },
{ "<A-K>", "<Cmd>VisualDuplicate -1<CR>", mode = { "x" }, desc = "Duplicate block up" },
{ "<A-J>", "<Cmd>VisualDuplicate +1<CR>", mode = { "x" }, desc = "Duplicate block down" },
},
},
-- Better character motion
{
"folke/flash.nvim",
event = "VeryLazy",
opts = {},
keys = {
{ "gj", function() require("flash").jump() end, mode = { "n", "x", "o" }, desc = "Flash" },
{
"gJ",
function() require("flash").treesitter() end,
mode = { "n", "x", "o" },
desc = "Flash Treesitter",
},
{ "r", function() require("flash").remote() end, mode = "o", desc = "Remote Flash" },
{
"R",
function() require("flash").treesitter_search() end,
mode = { "x", "o" },
desc = "Treesitter Search",
},
},
},
}