Edit a part of a file individually.
This plugin is designed mostly for editing code in markdown file.
For example, if you enable dotls in markdown file, you will get these errors.
To avoid the errors above, the plugin creates a new buffer for editing selected code.
- select code in virtual mode (only support "v" or "V" mode)
- use
require("part-edit").start()to create new buffer - save new buffer and the original file will also be updated.
-- default config
{
-- whether to save original file when update
save_original_file = true,
}-- keymap example
vim.keymap.set("v", "<space>p", function()
require("part-edit").start()
end, { silent = true, mode = "v" })-- add a strategy first
---@class PartEditStrategy
---@field name string
---@field from (fun(lines: string[]): string[]) | nil
---@field to (fun(lines: string[]): string[]) | nil
---@field file_suffix string
---@type fun(strategy: PartEditStrategy)
require"part-edit").add_strategy({
name = "js lines",
from = function(lines)
return vim.iter(lines)
:map(function(line)
return line:match('%"(.*)%"')
end)
:totable()
end,
to = function(lines)
return vim.iter(lines)
:map(function(line)
return string.format('"%s",', line)
end)
:totable()
end,
file_suffix = "js",
})