Closed tammersaleh closed 3 months ago
Using V
for visual line mode will automatically add extra lines before and after the surrounded text. You should either use v
for regular visual mode, or remove the extra beginning/ending lines from the configuration, i.e.
return { "```" .. result, "```" }
Thanks for the quick response! I'm struggling with the configuration structure... I tried what I think you're suggesting:
surrounds = {
["~"] = { -- Markdown fenced code blocks
add = function()
local config = require("nvim-surround.config")
local result = config.get_input("Markdown code block language: ")
-- 👇 Is this what you mean?
return { "```" .. result, "```" }
end,
},
},
But it gives this error when I try to use it:
Markdown code block language: rE5108: Error executing lua ...are/nvim/lazy/nvimsurround/lua/nvim-surround/config.lua:369: attempt to index a nil value stack traceback:
...are/nvim/lazy/nvim-surround/lua/nvim-surround/config.lua:369: in function 'get_delimiters'
...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:89: in function 'visual_surround'
[string ":lua"]:1: in main chunk
You've been so helpful, but can I ask you to show me where I got the config wrong?
Ah I forgot a set of curly braces, sorry about that! It should be:
surrounds = {
["~"] = { -- Markdown fenced code blocks
add = function()
local config = require("nvim-surround.config")
local result = config.get_input("Markdown code block language: ")
return { { "```" .. result }, { "```" } }
end,
},
},
Note to self: Probably parse the output of the add
function call in get_delimiters
to improve UX and avoid this footgun.
You should be able to set the tag to 2.3.0
(or just fetch latest from main
) for the original configuration I sent to work.
Thanks! The fixed configuration worked a charm!
Checklist
:h nvim-surround
to see if there might be any relevant information there?Neovim Version
Plugin Version
Tagged (Stable)
Minimal Configuration
Sample Buffer
Keystroke Sequence
VS~ruby<CR>
Expected behavior
Actual behavior
Additional context
Got the code from https://github.com/kylechui/nvim-surround/discussions/53#discussioncomment-8028781