-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for entering new surrounding in insert mode instead of prompt #145
Comments
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 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
where cough cough I'm writing documentation, and I am very tired of typing |
As of right now, using the default bindings in insert mode, |
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 |
I have solved this in my config by inserting --- Places the cursor on the nearest [CURSOR] occurrence.
--- This is useful when marking the cursor position in custom surroundings.
M.set_cursor = function()
local position = vim.fn.searchpos('\\[CURSOR\\]', 'n')
if position[1] == 0 and position[2] == 0 then
return
end
local line = position[1] - 1
local col = position[2] - 1
vim.api.nvim_buf_set_text(0, line, col, line, col + #"[CURSOR]", { "" })
vim.api.nvim_win_set_cursor(0, { line + 1, col })
vim.cmd('startinsert')
end return {
"kylechui/nvim-surround",
event = "VeryLazy",
config = function()
-- Override the default 'S' keymap to allow setting the cursor position
-- after surrounding.
vim.keymap.set("x", "S", function()
local curpos = require("nvim-surround.buffer").get_curpos()
return string.format(
":lua require('nvim-surround').visual_surround({ line_mode = false, curpos = { %d, %d }, curswant = %d }) require('custom.utils.surround').set_cursor()<CR>",
curpos[1],
curpos[2],
vim.fn.winsaveview().curswant
)
end, { desc = "Add a surrounding pair around a visual selection", silent = true, expr = true })
require("nvim-surround").setup({
keymaps = {
visual = false,
},
surrounds = {
["s"] = {
add = function()
local filetype = vim.bo.filetype
if filetype == "typescript" or filetype == "typescriptreact" or filetype == "javascriptreact" then
filetype = "javascript"
end
local statement_type = require("nvim-surround.config").get_input("Enter the statement type: ")
local map = {
["if"] = {
lua = { { "if [" .. "CURSOR" .. "] then " }, { " end" } },
rust = { { "if [" .. "CURSOR" .. "] { " }, { " }" } },
php = { { "if ([" .. "CURSOR" .. "]) { " }, { " }" } },
javascript = { { "if ([" .. "CURSOR" .. "]) { " }, { " }" } },
},
["try"] = {
php = { { "try { " }, { " }", "catch (\\Exception $e) {[" .. "CURSOR" .. "]}" } },
javascript = { { "try { " }, { " }", "catch (error) {[" .. "CURSOR" .. "]}" } },
},
}
if map[statement_type] and map[statement_type][filetype] then
return map[statement_type][filetype]
end
end,
},
},
})
end,
} Screen.Recording.2024-11-26.at.13.31.29.mov |
Checklist
: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.
The text was updated successfully, but these errors were encountered: