echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

[mini.ai] Allow to return a different region depending on the operator. #989

Closed oblitzitate closed 1 week ago

oblitzitate commented 1 week ago

Contributing guidelines

Module(s)

mini.ai

Description

For example, dd and yy applies on the whole line and the newline char, and cc applies from the first non-whitespace character to the end of the line.

Another example is dip, yip, and vip applies on the whole block and the newline char, and cip applies from the first non-whitespace character to the end of the line.

I would like to be able to create a textobject that applies differently depending on the operator.

Edit: I noticed, it's often the change operator that has a different starting position, so if not this feature request, then maybe a feature that allows to set where the change starts?

oblitzitate commented 1 week ago

Nevermind. I realized what I was looking for was to force linewise mode

echasnovski commented 1 week ago

Nevermind. I realized what I was looking for was to force linewise mode

Sure, this is already supported.

However, returning different region depending on the operator is also technically possible, as specification allows callable objects. Thus the returned region/pattern can be conditioned on vim.v.operator (see :h v:operator), but beware of doing so only in Operator-pending mode (not Visual).