Replace with Register Operator
- Neovim >= 0.10.0
Take a peek at these demo clips.
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.
- lazy.nvim
{
'tar80/rereope.nvim',
opts = {}, -- for requirements. rereope.nvim has no options.
keys = {
...
}
}
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
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.
RereopeHintBg
(defalut:PmenuSel
) Uses popup hintRereopeHintBorder
(default:PmenuSel
) Uses popup hintRereopeVisualFlash
(default:opts.beacon.hlgroup
orIncSearch
) Uses replaced linewise contents
-
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
andzP
is not supported.
The planned implementation has been completed. Next,
- write tests,
- fix bugs,
- write help document,
but I have other things to do, so I'll put it off.