Updates of ‘mini.surround’: tree-sitter support and more
Originally posted on Reddit
Hello, Neovim users!
I am happy to announce new features of ‘mini.surround’ - module of ‘mini.nvim’ for surrounding actions (add, delete, replace, find, highlight surrounding characters). All actions are dot-repeatable out of the box and operate on highly customizable set of surrounding identifiers. By default it defines mappings with common s
prefix (sa
for add, sd
for delete, sr
for replace, sf
for find, sh
for highlight), but setup similar to ‘tpope/vim-surround’ is, of course, also possible.
This update was prompted after the release of ‘mini.ai’ which can create custom textobjects. Its initial implementation was based on ‘mini.surround’ but in the process it got transformed into much more powerful design (at cost of some code and documentation complexity). Ironically, ‘mini.surround’ is now updated to share as much with ‘mini.ai’ as possible, which provides more integrated experience.
New features:
- New surrounding specification format for updated, more powerful search logic. This allows creating more flexible surroundings based on Lua patterns and functions. This also enables creating aliases (like new builtin
b
for brackets andq
for quotes). This is a breaking change for those who defined custom input surroundings. Previous format will work until next release and transition to new one is pretty straightforward. - Tree-sitter support. Thanks to new specification format you can now use tree-sitter based surroundings. More information is in the help file. Note, that for full experience with function call surrounding, better update ‘nvim-treesitter/nvim-treesitter-textobjects’ to at least include changes from this PR (merged around 3 days ago).
- “Last”/“next” extended mappings. With the same idea as in ‘mini.ai’, you can now use mappings with special suffixes (
l
for “last”,n
for “next”) to operate on previous or next surrounding. This can be done for actions involving searching surrounding (delete, replace, find, highlight) but proved to be especially useful for finding next surrounding (as shown in demo). - Support of
v:count
for input surrounding. Now, for example, you can type2sdf
to delete second (based on search method) function call. - For ‘tpope/vim-surround’ lovers, open bracket identifiers (
(
,[
,{
,<
) now include padding: for input it will use all edge whitespace, for output - single space.
Check it out and tell me what you think. Thanks!