Duplicate one or more lines. That's all.
Wrote this plugin with a lot of hints and motivations from duplicate.nvim.
Thanks.
- Duplicate the line with the cursor in normal mode.
- Duplicate the selected lines in V-LINE mode.
- Enable to specify the cursor position after duplication.
- Enable to make the duplicated range selected after duplication.
- Neovim >= 0.9.5
- Because it was developed with this version. Since it is simple, I think it will work even in lower versions.
Install the plugin with your preferred package manager. Here is an example in lazy.nvim.
{
'AT-AT/duplines.nvim',
config = function()
-- No need to execute unless you want to change the default option values.
require('duplines').setup({
-- options...
})
end,
}
Below are the configurable options and their default values.
{
-- The "range" here refers to the line-wise block of the source or destination.
-- The range to place the cursor on or select after duplication.
-- See documentation for available values and details.
target = 'dest',
-- The position within the range to place the cursor after duplication.
-- See documentation for available values and details.
cursor = 'head',
-- Whether the range should be selected or not after duplication.
select = false,
}
See the documentation for details.
This plugin does not provide a default keymap. Below is an example.
-- The options and behavior may be different from your intuition.
-- Please refer to the documentation for details.
-- Duplicate upwards, place the cursor on the first row of the destination range,
-- and do not select the destination range.
vim.keymap.set({ 'n', 'x' }, '<M-UP>', function()
-- Options can be specified as arguments for API.line().
require('duplines').line({ target = 'src', cursor = 'head', select = false }):duplicate()
end)
-- Duplicate downwards, place the cursor on the first row of the destination range,
-- and do not select the destination range.
vim.keymap.set({ 'n', 'x' }, '<M-DOWN>', function()
-- Options can also be specified in configuration methods.
require('duplines').line():dest():head():deselect():duplicate()
end)
If you are using Lazy.nvim, you can perform lazy loading at the same time by registering with the "keys" option.
{
keys = {
{
'<M-Up>',
function()
require('duplines').line():src():head():deselect():duplicate()
end,
mode = { 'n', 'x' },
},
{
'<M-Down>',
function()
require('duplines').line():dest():head():deselect():duplicate()
end,
mode = { 'n', 'x' },
},
},
}