Why another surround plugin?
The answer is simple: because I only ever used the 'surround visual selection' feature of (btw incredible) plugins such as
nvim-surround or mini.surround.
I wanted to create the plugin that does a similar thing to that one vsc**e's feature - highlight text that you want to surround
with parentheses and just press the (
or )
key.
If you want additional functionalities, such as deleting surrounding characters, changing surrounding characters, or some other advanced features, check out two of the plugins mentioned above.
visual-surround_showcase.mp4
lazy:
{
"NStefan002/visual-surround.nvim",
config = function()
require("visual-surround").setup({
-- your config
})
end,
-- or if you don't want to change defaults
-- config = true
}
use({
"NStefan002/visual-surround.nvim",
config = function()
require("visual-surround").setup({
-- your config
})
end,
})
Default config
{
-- if set to true, the user must manually add keymaps
use_default_keymaps = true,
-- will be ignored if use_default_keymaps is set to false
surround_chars = { "{", "}", "[", "]", "(", ")", "'", '"', "`" },
-- whether to exit visual mode after adding surround
exit_visual_mode = true,
}
set some additional keymaps
vim.keymap.set("v", "s<", function()
-- surround selected text with "<>"
require("visual-surround").surround("<") -- it's enough to supply only opening or closing char
end)
set new keymaps
require("visual-surround").setup({
use_default_keymaps = false,
})
local preffered_mapping_prefix = "s"
local surround_chars = { "{", "[", "(", "'", '"', "<" }
local surround = require("visual-surround").surround
for _, key in pairs(surround_chars) do
vim.keymap.set("v", preffered_mapping_prefix .. key, function()
surround(key)
end, { desc = "[visual-surround] Surround selection with " .. key })
end