Skip to content

tar80/rereope.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rereope.nvim

Replace with Register Operator

Requirements

  • Neovim >= 0.11.0

Demo

Take a peek at these demo clips.

rereope_standard

rereope_blockwise

rereope_FIFO

rereope_expression

rereope_registers

rereope_flash

Usage

Rereope provides only one method rereope.open.

rereope.open first inputs the trigger key, followed by the register key.
For example: <trigger-key>[register-key]{motion}.

Additionally, it is also possible to perform the operation in the original way
by inputting the register key first, followed by the trigger key.
For example: "[register-key]<trigger-key>{motion}

It is also possible to set an alternative-key for the unnamed register. This can be done by placing the trigger key and the alternative-key in close proximity (or assigning them to the same key), which can lead to a reduction in key operation effort.

---@param alternative-key string|nil
-- The specified key will be used as a alternative key for the unnamed register.
---@param options RereopeOptions
rereope.open(alternative-key, { end_point, beacon, hint, motion, replace })

---@class RereopeOptions

---@field end_point boolean
--- Move cursor to end of past range.

---@field beacon [ hlgroup:string, interval:integer, winblend:integer, decay:integer ]
---  Flash the replaced text.

---@field hint { winblend:integer, border:string[]|nil } Floating window option values
--- Popup hint select register contents.

---@field motion fun()
--- Automatically execute motion after register selection.

---@field replace {
---         mode:string|nil,
---         regname:string|nil,
---         regtype:string|nil,
---         fallback: fun(line:string):line:string
---       }
--- Format the register contents before pasting them.
--- Specifying `mode`, `regname`, and `regtype` will perform conditional judgment.
--- You can use fallbacks to process replacements line by line.

Installation

  • lazy.nvim
{
    'tar80/rereope.nvim',
    opts = {
        map_cyclic_register_keys = nil -- { prev = '<C-p>', next = '<C-n>' },
    },
    keys = {
        ...
    }
}

Note

map_cyclic_register_keys has been added. Passing a table to this value adds an omap to cycle through registers 0-9 in rereope's operator-pending mode.

rereope_cycle_registers

Configurations

Standard replace
local opts = {
    end_point = true,
    beacon = {},
    hint = {},
}

-- Respects vim-operator-replace
vim.keymap.set({'n', 'x'}, '_', function()
    local opts = {}
    return require('rereope').open('_', opts)
end, {desc = 'Rereope open'})

-- Respects vim-ReplaceWithRegister
vim.keymap.set({'n', 'x'}, 'gr', function()
    local opts = {}
    return require('rereope').open('r', opts)
end, {desc = 'Rereope open'})
-- Linewise auto motion
vim.keymap.set({'n', 'x'}, 'gR', function()
    local opts = {
        motion = function()
            vim.api.nvim_input('_')
        end,
    }
    return require('rereope').open('R', opts)
end, {desc = 'Rereope open linewise'})
FIFO with format

When the replace option is specified with a fallback and a numbered register is expanded and pasted, FIFO mode becomes active. In this mode, each time the dot repeat (.) is used, the number of the next numbered register to be expanded is automatically incremented.

local opts = {
    end_point = false,
    beacon = { 'IncSearch', 100, 0, 15 },
    hint = { winblend = 20, border = { '+', '-' } },
    replace = {
        fallback = function(line)
            return string.format('<%s>', line)
        end
    }
}
With Flash.nvim
local opts = {
    motion = function()
      if vim.treesitter.get_node() then
        require('flash').treesitter()
      end
    end,
}

However, special operations such as Remote Actions may not work correctly. You can execute a Remote Actions by calling it normally as an operator without using the motion option.

Highlights

  • RereopeHintBg (defalut:PmenuSel) Uses popup hint
  • RereopeHintBorder (default:PmenuSel) Uses popup hint
  • RereopeVisualFlash (default:IncSearch) Uses replaced linewise contents

Issues

  • Regarding the beacon functionality, it has been replaced with a built-in feature due to the considerable effort required for its application to the visual-mode range. It is currently undecided whether we will address this functionality in the future.

  • Pasting blocwise excluding spaces such as zp and zP is not supported.

ToDo

The planned implementation has been completed. Next,

  • write tests,
  • fix bugs,
  • write help document,

Acknowledgment

About

Replace with register operator

Topics

Resources

License

Stars

Watchers

Forks

Languages