Repository navigation
User defined search and replace #4
Description
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
search-replace.nvim/lua/search-replace/single-buffer.lua
Lines 6 to 25 in b3485c9
| 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