nvim-surround
nvim-surround copied to clipboard
Add support for entering new surrounding in insert mode instead of prompt
Checklist
- [x] Have you read through
:h nvim-surround
to see if there might be any relevant information there?
Is your feature request related to a problem? Please describe.
When using something like csf to change a function call, there is a prompt for entering the new function name. This means I can't take advantage of LSP autocompletion when typing the new name.
Describe the solution you'd like
Have an option to enter insert mode for typing in the new name instead of the prompt.
Hi there, adding this in would require a non-trivial refactor and I probably won't do it anytime soon (although it is quite an interesting idea). However, a workaround you could try is to hit the key combination csf<CR>i
. That way it should just delete the function name (but leaving the parentheses), and then you can use LSP auto-completion to your heart's content. For your convenience, here's a keymap that you can use for the time being, although note that it's not part of the official API and could break in subsequent updates:
vim.keymap.set("n", "csf", function()
vim.schedule(function()
require("nvim-surround").change_surround({
del_char = "f",
add_delimiters = function()
return { { "" }, { "" } }
end,
curpos = require("nvim-surround.buffer").get_curpos(),
})
end)
return "i"
end, { silent = true, expr = true })
I'll be leaving this issue open as the above is just a workaround; please let me know if it helped!
Sounds cool, thanks for the workaround!
this would be a useful feature if only to insert xml-style tags (when you're not in xml/html/etc). So, something like <C-s>t
in insert mode would spawn some sort of input()
(like s<motion>t
in normal mode) and then typing "code" would give you
<code>|</code>
where |
is the cursor of course ("on" the '<' of "</code>" but in insert mode).
cough cough I'm writing documentation, and I am very tired of typing <code>bla bla bla
then remembering to write </code>
at the end.
As of right now, using the default bindings in insert mode, <C-g>stcode<CR>
does the behavior that you want. However, if you find yourself doing a lot of surrounds involving <code>
tags, I would recommend making a custom surround.
I am so sorry. I was using a different plugin, and I really thought I had come to the right repo. Thanks & sorry
No worries! Maybe now you'll have some incentive to switch to nvim-surround
:wink: