Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/nvim-surround.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ surrounds, for example setting up a `$` surround, but only in bash files:
add = { "${", "}" },
find = "$%b{}",
delete = "^(..)().-(.)()$",
label = "${…}",
},
},
})
Expand Down Expand Up @@ -540,6 +541,9 @@ containing the following keys:
are directly used as the replacement pair. For example, when changing HTML
tag types, only `cst` is needed, instead of `cstt`.

*nvim-surround.setup.surrounds.label*
label: ~
An optional string that represents the label for the surround.

*nvim-surround.setup.surrounds.invalid_key_behavior*
`invalid_key_behavior` is a special key in the `surrounds` table that defines
Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-surround/annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
---@field find find_func
---@field delete delete_func
---@field change change_table
---@field label? string

---@class options
---@field surrounds table<string, surround>
Expand All @@ -51,6 +52,7 @@
---@field find? user_find
---@field delete? user_delete
---@field change? user_change
---@field label? string

---@class user_options
---@field surrounds? table<string, false|user_surround>
Expand Down
16 changes: 16 additions & 0 deletions lua/nvim-surround/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,87 @@ M.default_opts = {
return M.get_selection({ motion = "a(" })
end,
delete = "^(. ?)().-( ?.)()$",
label = "( ... )",
},
[")"] = {
add = { "(", ")" },
find = function()
return M.get_selection({ motion = "a)" })
end,
delete = "^(.)().-(.)()$",
label = "(...)",
},
["{"] = {
add = { "{ ", " }" },
find = function()
return M.get_selection({ motion = "a{" })
end,
delete = "^(. ?)().-( ?.)()$",
label = "{ ... }",
},
["}"] = {
add = { "{", "}" },
find = function()
return M.get_selection({ motion = "a}" })
end,
delete = "^(.)().-(.)()$",
label = "{...}",
},
["<"] = {
add = { "< ", " >" },
find = function()
return M.get_selection({ motion = "a<" })
end,
delete = "^(. ?)().-( ?.)()$",
label = "< ... >",
},
[">"] = {
add = { "<", ">" },
find = function()
return M.get_selection({ motion = "a>" })
end,
delete = "^(.)().-(.)()$",
label = "<...>",
},
["["] = {
add = { "[ ", " ]" },
find = function()
return M.get_selection({ motion = "a[" })
end,
delete = "^(. ?)().-( ?.)()$",
label = "[ ... ]",
},
["]"] = {
add = { "[", "]" },
find = function()
return M.get_selection({ motion = "a]" })
end,
delete = "^(.)().-(.)()$",
label = "[...]",
},
["'"] = {
add = { "'", "'" },
find = function()
return M.get_selection({ motion = "a'" })
end,
delete = "^(.)().-(.)()$",
label = "'...'",
},
['"'] = {
add = { '"', '"' },
find = function()
return M.get_selection({ motion = 'a"' })
end,
delete = "^(.)().-(.)()$",
label = '"..."',
},
["`"] = {
add = { "`", "`" },
find = function()
return M.get_selection({ motion = "a`" })
end,
delete = "^(.)().-(.)()$",
label = "`...`",
},
["i"] = { -- TODO: Add find/delete/change functions
add = function()
Expand All @@ -90,6 +101,7 @@ M.default_opts = {
end,
find = function() end,
delete = function() end,
label = "?...?",
},
["t"] = {
add = function()
Expand Down Expand Up @@ -123,6 +135,7 @@ M.default_opts = {
end
end,
},
label = "<tag>...</tag>",
},
["T"] = {
add = function()
Expand Down Expand Up @@ -156,6 +169,7 @@ M.default_opts = {
end
end,
},
label = "<tag>...</tag>",
},
["f"] = {
add = function()
Expand Down Expand Up @@ -188,6 +202,7 @@ M.default_opts = {
end
end,
},
label = "function(...)",
},
invalid_key_behavior = {
-- By default, we ignore control characters for adding/finding because they are more likely typos than
Expand Down Expand Up @@ -485,6 +500,7 @@ M.translate_surround = function(char, user_surround)
find = M.translate_find(user_surround.find),
delete = M.translate_delete(char, user_surround.delete),
change = M.translate_change(char, user_surround.change),
label = user_surround.label,
}
end

Expand Down
Loading