Skip to content

User defined search and replace #4

Open

Description

@danielo515

Hello, this plugin is great. I didn't knew how useful it could be until I started using it, thanks.

I think it will be wonderful if users could use their own patters. There are several patterns that I repeat often that are hard to type. Will be lovely to be able to map them using your plugin.

I can just try something like this:

keymap["r"]["n"] = {
  function()
    local search = require("search-replace.single-buffer").search_replace
    search(vim.fn.expand "<cword>" .. "\\_")
  end,
  "include [n]ewline",
}

However, your function does some double escaping in the provided pattern

M.search_replace = function(pattern)
local shift = 0
if string.len(pattern) == 0 then
shift = 2
else
shift = 1
end
local left_keypresses =
string.rep("\\<Left>", string.len(config.options["default_replace_single_buffer_options"]) + shift)
vim.cmd(
':call feedkeys(":%s/'
.. util.double_escape(pattern)
.. "//"
.. config.options["default_replace_single_buffer_options"]
.. left_keypresses
.. '")'
)
end

therefore this will not work properly. What about making that function take an extra option with special characters to include or something like that? something like pre and post options to the provided pattern?

If you don't want to broad the scope of your plugin, that is fine too!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions