niuiic/part-edit.nvim

github github
editing-support
stars 14
issues 0
subscribers 1
forks 0
CREATED

UPDATED


part-edit.nvim

Edit a part of a file individually.

More neovim plugins

Usage

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.

  1. select code in virtual mode (only support "v" or "V" mode)
  2. use require("part-edit").start() to create new buffer
  3. save new buffer and the original file will also be updated.

Dependencies

Config

-- 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",
})