Remote relative line operations for Neovim.
relops.nvim lets you act on lines away from the cursor without jumping to them first. It is useful when relative numbers show the target lines clearly and you want to delete, yank, change, or move those lines while keeping your cursor anchored.
- Neovim 0.9+
{
"kvnduff/relops.nvim",
opts = {},
}use {
"kvnduff/relops.nvim",
config = function()
require("relops").setup()
end,
}Plug 'kvnduff/relops.nvim'Then configure it from Lua:
require("relops").setup()-- lazy.nvim
{
dir = "~/projects/relops/relops.nvim",
name = "relops.nvim",
opts = {},
}
-- packer.nvim
use {
"/home/kevin/projects/relops/relops.nvim",
config = function()
require("relops").setup()
end,
}The default mappings are:
| Mapping | Operation |
|---|---|
dr |
Delete a remote relative line range |
yr |
Yank a remote relative line range |
cr |
Change a remote relative line range |
mr |
Move a remote relative line range |
After the operation mapping, type a compact range expression using relative line counts and j or k directions.
dr15j18j delete the range from 15 lines below through 18 lines below
yr5k10k yank the range from 5 lines above through 10 lines above
cr5k8j change the range from 5 lines above through 8 lines below
Single-line shorthand repeats the same target when both directions match:
dr15jj delete the line 15 lines below
yr15kk yank the line 15 lines above
Move syntax includes a source range and a destination. The moved lines are inserted before the destination line.
mr2j3j13j move 2j..3j before the line 13j from the cursor
Move-to-here shorthand uses a final repeated direction instead of an explicit destination count:
mr13kkk move the line 13k to the current cursor line
mr5k8jj move 5k..8j to the current cursor line
Moving into the selected source range is rejected and does not mutate the buffer.
Default configuration:
require("relops").setup({
mappings = {
enabled = true,
delete = "dr",
yank = "yr",
change = "cr",
move = "mr",
},
yank_highlight = {
enabled = true,
group = "IncSearch",
duration = 180,
},
clipboard = {
unnamed = true,
yank_register = true,
delete_register = true,
system = true,
selection = true,
},
undo = {
wrap = false,
},
notifications = true,
})By default, relops.nvim does not map u or <C-r>. That keeps the plugin non-invasive for public use.
If you want undo and redo to restore the cursor/view position around remote operations, opt in:
require("relops").setup({
undo = {
wrap = true,
},
})local relops = require("relops")
relops.setup(opts)
relops.delete()
relops.yank()
relops.change()
relops.move()
relops.undo()
relops.redo()- Input after
dr,yr,cr, ormris read withgetcharstr(), so nativeshowcmddoes not display the in-progress command. - The command parser intentionally accepts only the compact relative-line grammar documented above.
- Clipboard writes to
+and*are attempted when enabled, but ignored safely when those registers are unavailable. - Undo and redo wrapping is optional because overriding
uand<C-r>is invasive.
MIT