Update of ‘mini.ai’

update
reddit
Now supports textobjects based on tree-sitter
Author

Evgeni Chasnovski

Published

August 7, 2022

Originally posted on Reddit

‘mini.ai’ is a module of ‘mini.nvim’ plugin for extending and creating a/i textobjects (like in di( or va"). You can see more info in the announcement and help file.

Now it has support for tree-sitter specifications via exported MiniAI.gen_spec.treesitter() function. In order for this to work, user should have ‘textobjects’ query files with specified captures for every target language. Can have them either by just installing ‘nvim-treesitter/nvim-treesitter-textobjects’ (but not enabling textobjects) or creating manually inside ‘after/queries/<language>/textobjects.scm’ files.

You can see here a detailed comparison between ‘mini.ai’ and ‘nvim-treesitter-textobjects’. In short: ‘nvim-treesitter-textobjects’ ships with queries while ‘mini.ai’ doesn’t; ‘mini.ai’ supports v:count, different search methods, consecutive application (incremental selection of same textobjects), and next/last textobject variations while ‘nvim-treesitter-textobjects’ doesn’t.

Although the main purpose of ‘mini.ai’ is to create plain text textobjects which are useful most of the times (brackets, quotes, underscores, etc), it was designed to allow extensions via Lua functions. After a bit of beta-testing, Oliver Leete made a great suggestion about a minimal change in API to enable very convenient textobject specifications. Thanks to that, now it is possible.

Edit: thanks to suggestion, latest main branch now supports array of captures instead of a single capture. So users can define something like MiniAi.gen_spec.treesitter({ a = { '@conditional.outer', '@loop.outer' }, i = { '@conditional.inner', '@loop.inner' } }) (it will pick best region among all supplied matches).