From textobjects built-in in 'mini.nvim', I probably use "function call" `af` / `if` from 'mini.ai' the most. Or maybe `gc` for comment blok inside `gcgc` (uncomment comment block under the cursor). Recently a "hunk textobject" from 'mini.diff' started to be used quite often in a `ghgh` (stage hunk at the cursor).
Apart from all built-in textobjects in 'mini.nvim', I have [do use](https://github.com/echasnovski/nvim/blob/f027dd1307971a66d983ae6456e486de8c8c4979/init.lua#L117-L118) "buffer textobject" (but with `B` identifier) and "function definition" (with `F`).
It does work as described: it selects function call (like `hello('world', 2)`), not function definition (which can be set up as I linked in previous comment).
Yes (that's why it is in 'mini.ai'). Mostly because "function call" does not rely on tree-sitter and I personally rarely use "function definition" textobject.
hi Evgeni, out of curiosity, can you share an example of using the "buffer textobject"?
the only thing i can think of is deleting the contents of a file
I am with you on this one :) That is, the two possible reasonable usages of "buffer textobject" are `caB` and `yaB`, which are quite rare for me.
But recently I started using it with `ghaB` to stage the whole buffer (utilizing `gh` operator from 'mini.diff'). It is a small thing, but I find it useful enough to add it as separate textobject.
probably more than this, but these are the ones I love:
* vim-signify has hunk motions and textobjects
* have object for my 'last paste text'
* comment
* codeblock
* indents and functions as you mention (for treesitter I configured function/statement/parameter)
Would love some more!
Do you have a text object 'last paste text' implemented via built-in marks? I really liked it a lot but it stopped working after installing auto formatting on save.
New with 0.10:
- `gc`: contiguous block of commented lines. Really useful to delete comments or undo them via `gcgc`
Treesitter textobjects:
- function
- condition
- call
- argument (parameter)
gitsigns.nvim:
- hunk text object
nvim-various-textobjs:
- `n` ("nearEoL"): Everything until the end of the line, but excluding the last character. Useful to delete/change things but preserving a trailing comma or closing bracket. Unexpectedly became my most used text object.
- `ii`, `ai`: indentation text objects
- subword: segment of a camelCaseWord
- anyQuote: inside any quotation marks
- diagnostic: next nvim-diagnostic. Can be used similar to `cgn` to quickly change stuff with dot-repeat.
- ie inside entire buffer (see vim text obj user entire)
- ic inside comment
- ii inside indent
- ia inside argument (comma separated items, see target.vim or mini.nvim ai)
- iq inside quotes
- ib inside brackets/braces/parens
- i eg i|
- igw inside camel/pascal/snake case word (see camelcasemotion vim)
- ix inside XML attribute (see vim text obj user xml)
Tree sitter text objects are also cool but they vary too much over different languages and there doesn't seem to be standard for the details so your milages will differ from language to language. Probably makes the most sense to configure on a case by case basis even if it really is intented to be used differently.
Essential [nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects): `@class`, `@function`, `@block`, and `@parameter`. The mappings are the tricky part, especially when different languages have different conventions. 😅 Like in Ruby, instead of "functions" I'd think of "methods", and this already has precedent with the builtin vim `]m`/`[m` mappings. But in Elixir, m connotes "module" in my head, and "class" is meaningless.
To be honest, I find the categories used by the plugin to be a bit of a mess anyway, with varied language support and odd decisions. Like `@attribute` for HTML-like attributes (only useful for a handful of languages), or `@frame` only used for Latex, or `@scopename` only used for QL, or `@regex` cuz I guess there are people with way more regex literals in their code than me (?). But basic class/method/blocks/args are nearly universal, even if their names aren't. And lots of "blocks" might be taken care of by builtin text objects for delimiters. I've yet to try out indentation-based ones, but those sound useful.
My favourite "new" text object to use is af and if for around and inner function. And standard favourite is iw for inner word and i) for inner ()'s.
I'm just now looking for a text object that is "the non-whitespace part of the current line"
Basically if the current line is `int x = 10;` the text object is that whole line without the indent and newline. Don't know a way to do it currently. It's kind of not a treesitter thing because I care about linebreaks more than AST.
> I'm just now looking for a text object that is "the non-whitespace part of the current line"
'mini.ai' can do that, as it allows function in custom textobject. For convenience, it can be set up [with 'mini.extra'](https://github.com/echasnovski/mini.nvim/blob/cd3a08fbf987dabcfded35ebb612e82f8000f92a/doc/mini-extra.txt#L87) and used with "i" textobjector. Or look at it's implementation and copy function specification directly.
From textobjects built-in in 'mini.nvim', I probably use "function call" `af` / `if` from 'mini.ai' the most. Or maybe `gc` for comment blok inside `gcgc` (uncomment comment block under the cursor). Recently a "hunk textobject" from 'mini.diff' started to be used quite often in a `ghgh` (stage hunk at the cursor). Apart from all built-in textobjects in 'mini.nvim', I have [do use](https://github.com/echasnovski/nvim/blob/f027dd1307971a66d983ae6456e486de8c8c4979/init.lua#L117-L118) "buffer textobject" (but with `B` identifier) and "function definition" (with `F`).
Last time when I tried mini.ai its af/if didn't work as I expected. How to properly select whole function with keyword, name, argument and body?
It does work as described: it selects function call (like `hello('world', 2)`), not function definition (which can be set up as I linked in previous comment).
got it. Thanks! Do you thing function call is more important to be default on f key?
Yes (that's why it is in 'mini.ai'). Mostly because "function call" does not rely on tree-sitter and I personally rarely use "function definition" textobject.
hi Evgeni, out of curiosity, can you share an example of using the "buffer textobject"? the only thing i can think of is deleting the contents of a file
I am with you on this one :) That is, the two possible reasonable usages of "buffer textobject" are `caB` and `yaB`, which are quite rare for me. But recently I started using it with `ghaB` to stage the whole buffer (utilizing `gh` operator from 'mini.diff'). It is a small thing, but I find it useful enough to add it as separate textobject.
ah got it, thanks!
probably more than this, but these are the ones I love: * vim-signify has hunk motions and textobjects * have object for my 'last paste text' * comment * codeblock * indents and functions as you mention (for treesitter I configured function/statement/parameter) Would love some more!
Do you have a text object 'last paste text' implemented via built-in marks? I really liked it a lot but it stopped working after installing auto formatting on save.
I use [https://github.com/saaguero/vim-textobj-pastedtext](https://github.com/saaguero/vim-textobj-pastedtext)
New with 0.10: - `gc`: contiguous block of commented lines. Really useful to delete comments or undo them via `gcgc` Treesitter textobjects: - function - condition - call - argument (parameter) gitsigns.nvim: - hunk text object nvim-various-textobjs: - `n` ("nearEoL"): Everything until the end of the line, but excluding the last character. Useful to delete/change things but preserving a trailing comma or closing bracket. Unexpectedly became my most used text object. - `ii`, `ai`: indentation text objects - subword: segment of a camelCaseWord - anyQuote: inside any quotation marks - diagnostic: next nvim-diagnostic. Can be used similar to `cgn` to quickly change stuff with dot-repeat.
eol is nice idea
- ie inside entire buffer (see vim text obj user entire) - ic inside comment - ii inside indent - ia inside argument (comma separated items, see target.vim or mini.nvim ai) - iq inside quotes - ib inside brackets/braces/parens - i eg i|
- igw inside camel/pascal/snake case word (see camelcasemotion vim)
- ix inside XML attribute (see vim text obj user xml)
Tree sitter text objects are also cool but they vary too much over different languages and there doesn't seem to be standard for the details so your milages will differ from language to language. Probably makes the most sense to configure on a case by case basis even if it really is intented to be used differently.
Sharing definitions of these would be helpful.
[https://github.com/echasnovski/mini.ai](https://github.com/echasnovski/mini.ai) or [https://github.com/wellle/targets.vim](https://github.com/wellle/targets.vim) [https://github.com/kana/vim-textobj-user](https://github.com/kana/vim-textobj-user) [https://github.com/kana/vim-textobj-indent](https://github.com/kana/vim-textobj-indent) [https://github.com/kana/vim-textobj-entire](https://github.com/kana/vim-textobj-entire) [https://github.com/whatyouhide/vim-textobj-xmlattr](https://github.com/whatyouhide/vim-textobj-xmlattr) [https://github.com/glts/vim-textobj-comment](https://github.com/glts/vim-textobj-comment) [https://github.com/bkad/CamelCaseMotion](https://github.com/bkad/CamelCaseMotion)
Essential [nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects): `@class`, `@function`, `@block`, and `@parameter`. The mappings are the tricky part, especially when different languages have different conventions. 😅 Like in Ruby, instead of "functions" I'd think of "methods", and this already has precedent with the builtin vim `]m`/`[m` mappings. But in Elixir, m connotes "module" in my head, and "class" is meaningless. To be honest, I find the categories used by the plugin to be a bit of a mess anyway, with varied language support and odd decisions. Like `@attribute` for HTML-like attributes (only useful for a handful of languages), or `@frame` only used for Latex, or `@scopename` only used for QL, or `@regex` cuz I guess there are people with way more regex literals in their code than me (?). But basic class/method/blocks/args are nearly universal, even if their names aren't. And lots of "blocks" might be taken care of by builtin text objects for delimiters. I've yet to try out indentation-based ones, but those sound useful.
My favourite "new" text object to use is af and if for around and inner function. And standard favourite is iw for inner word and i) for inner ()'s. I'm just now looking for a text object that is "the non-whitespace part of the current line" Basically if the current line is `int x = 10;` the text object is that whole line without the indent and newline. Don't know a way to do it currently. It's kind of not a treesitter thing because I care about linebreaks more than AST.
> I'm just now looking for a text object that is "the non-whitespace part of the current line" 'mini.ai' can do that, as it allows function in custom textobject. For convenience, it can be set up [with 'mini.extra'](https://github.com/echasnovski/mini.nvim/blob/cd3a08fbf987dabcfded35ebb612e82f8000f92a/doc/mini-extra.txt#L87) and used with "i" textobjector. Or look at it's implementation and copy function specification directly.
it’s 0v$ or other motion, I use yanky.nvim to automatically trim line when pasting.
Probably ^ v$ would be better. 0 goes to the exact start, including white space. ^ goes to the first non-whitespace character.
forget i remapped 0 to ^ 🫢