Skip to content

A Neovim plugin allows you to perform an action on where you can see.

Notifications You must be signed in to change notification settings

Weissle/easy-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easy-action

GitHub Workflow Status Lua

easy-action is a plugin which allows you to execute an action, such as yank and delete, but keeps your cursor position.

It bases on EasyMotion-like plugins. When use EasyMotion-like plugin, you need to trigger them and choose the position you jump. For easy-action, you need to trigger easy-action, input your action, choose where to perform the action.

In the below example, my cursor is on the left window and I will copy and delete the text on the right window which is around 45 line. In this example, I use <space>e to trigger easy-action.

2022-10-30.23-48-24.mp4

Background

With the easy-motion like plugin, we can easily jump to anywhere visible. However, it is not so easy to execute an action on where is visible. Think about how many keys we need to press if we want to yank or delete something which is not under our cursor.

Status

The whole plugin's status is alpha. Your feedbacks are very important to the easy-action's improvement.
I use hop.nvim, supporting other relative plugins maybe slow.Thus, PR is welcome.

Currently supported Plugins:

Install

With packer.nvim

use {
  'Weissle/easy-action',
  requires = {
    {
      "kevinhwang91/promise-async",
      module = { "async" },
    }
  }
}

Config

-- Below setting is default and you don't need to copy it. You may just require("easy-action").setup({})
require("easy-action").setup({
  -- These chars can show up any times in your action input.
  free_chars = "0123456789",
  -- These chars can show up no more than twice in action input.
  limited_chars = "iafFtT",
  -- Cancel action.
  terminate_char = "<ESC>",
  -- all action contains `key` will be replaced by `value`. For example yib -> yi(
  remap = {
    ib = "i(",
    ab = "a(",
  },
  -- Default jump provider
  jump_provider = "hop",
  jump_provider_config = {
    hop = {
      action_select = {
        char1 = {
          -- action ends with any char of options will use HopChar1MW command.
          options = "(){}[]<>`'\"",
          cmd = "HopChar1MW",
          feed = function(action)
            return string.sub(action, #action)
          end,
        },
        line = {
          -- action ends with any char of options will use HopLineMW command.
          options = "yd",
          cmd = "HopLineMW",
        },
        -- Default command.
        default = "HopChar2MW",
      },
    },
    leap = {
      action_select = {
        default = function()
          require("leap").leap({ target_windows = require("leap.util").get_enterable_windows() })
        end,
      },
    },
  },
  -- Just make sure they are greater than 0. Usually 1 is all right.
  jump_back_delay_ms = 1,
  feed_delay_ms = 1,
})

Use other jump plugins

require("easy-action").setup({
  jump_provider = "other_jump_plugin_name",
  jump_provider_config = {
    other_jump_plugin_name = function(action)
      -- Your will get the action which is going to be executed. And you can choose your jump command. 
      -- It can be string, then easy-action will do vim.cmd(ret).
      -- It can be function, then easy-action will call ret().
      -- It can be table, {cmd = string|function, feed = string}, then easy-action will execute this cmd and feed the `feed`.
    end
  }
})

Usage

easy-action doesn't change your keymap by default. You may

local opts = { silent=true, remap=false }
-- trigger easy-action.
vim.keymap.set("n","<leader>e", "<cmd>BasicEasyAction<cr>", opts)

-- To insert something and jump back after you leave the insert mode
vim.keymap.set("n","<leader>ei", function()
  require("easy-action").base_easy_action("i", nil, "InsertLeave")
end, opts)

-- run :h base_easy_action() to see more details about the base_easy_action.

About

A Neovim plugin allows you to perform an action on where you can see.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published