Closed kevintraver closed 1 month ago
What do you mean by that? Simply switching search and replace lines? Not sure what the use case would be, but that would just be ddp
.
Or do you mean sth else?
Right now when you open the popup, it starts in insert mode in the Search Input. Then to switch to to the Replace input, you have to escape, and then move (j
) to the Replace input.
I was hoping to have something like tab
, where you could switch between the Search Input and Replace input without leaving insert mode.
I dunno. Arrow-down and arrow-up would cover this already (which can be remapped of course). Having that on one hotkey feels a bit too niche to add to the plugin.
Nonetheless, you can create a function that does what you want with 2-3 lines of code and map it to the file type rip-substitute
. Sth like "if on first line, move down, otherwise move up"
I threw together a draft PR if you wanted to check it out, because I think it might be useful. If you still don't want to use it, no worries I can add it to my own config!
I also made it to where it remembers cursor position when switching between inputs.
Just for reference, here is what I ended up doing
{
"<tab>",
mode = { "n", "i" },
function()
--- @class RipSubstituteState
--- @field cursorPositions table<number, number>
local state = require("rip-substitute.state").state
if state.cursorPositions == nil then
state.cursorPositions = { [1] = 0, [2] = 0 }
end
local cursorPos = vim.api.nvim_win_get_cursor(state.popupWinNr)
state.cursorPositions[cursorPos[1]] = cursorPos[2]
local line = cursorPos[1] == 1 and 2 or 1
local col = state.cursorPositions[line] or 0
vim.api.nvim_win_set_cursor(state.popupWinNr, { line, col })
end,
ft = "rip-substitute",
}
Demo using the <tab>
key to between Search and Replace, while remembering position
Checklist
Feature Requested
It would be useful to have a function to easily switch between Search and Replace inputs.
This could then be mapped by the user to something like
<tab>
.Relevant Screenshot
No response