chrisgrieser / nvim-various-textobjs

Bundle of more than 30 new text objects for Neovim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FR: indentation-object if indentation-level is 0

astier opened this issue · comments

Bug Description

If the indent-level is 0 then the indent-object doesn't work. It says Current line is not indented. This behavior is different from https://github.com/kana/vim-textobj-indent and https://github.com/michaeljsmith/vim-indent-object and I would consider wrong. Some of my mappings and usecases break if text with an indent-level of 0 isn't recognized as an object of the same indent. Whatever the indent-level is I want to perform operations on text of the same indent even if its 0. Could this be changed? Thank you.

Relevant Screenshot

No response

To Reproduce

  1. Move cursor over text which is not indented (indent-level 0)
  2. Press vii to visually select all text of the same indent
  3. See the message in the cmdline Current line is not indented

neovim version

0.8.3

Make sure you have done the following

  • I have updated to the latest version of the plugin.

This is not a bug but the intended behavior though

Also, regardless whether this is a bug or a Feature request, there is little I can do if you do not describe what behavior you expect at indention level zero - applying the logic of "everything with the same indent", vii would select the entire file.

applying the logic of "everything with the same indent", vii would select the entire file

This is correct. Apply the same logic as with every other indent.

The fact that vii would select the whole file (or with indent > 0 all the lines with the respective indent) including lines which are separated by empty lines is actually another issue which I wanted to open as a separate issue. I would expect (and this is again how the other two indent-plugins behave) that via should behave like vii behaves right now and select all text with the same indent including lines which are separated by empty lines . vii should only select the text with the same indent but stop at empty lines (similar to vip to select the current paragraph). Then viI could behave like vai behaves right now. But again I should probably open it as a separate issue with examples. Just wanted to mention it because the example of how vii should behave came up.

applying the logic of "everything with the same indent", vii would select the entire file
This is correct. Apply the same logic as with every other indent.

But for that, there is already the the entireBuffer textobj which you can use. I am not super inclined to implement that behavior for ii, since I think it's more often by accident than by intention that you use ii there. Closing this since I assume that such a behavior is not desired by most users.

If you really want ii to also work as entireBuffer on indention level 0, you could create a two-line-snippet using vim.fn.indent and expr to switch between ii and entireBuffer depending on the current indentation level. 🙂


Concerning the different behavior of ii and family: I kinda implemented the indent textobj in the same way that I was familiar with it. I personally think making the indent-textobj only consider indentation-changes as delimiters is more useful, since for vim's ip already considers blank lines as delimiters. If you nevertheless want such a combined textobj, please open a new FR and I'll look into it if there is more demand for that.

I assume that such a behavior is not desired by most users.

I would like to gently disagree. I tried

They all don't treat indent of 0 as a special case. Which means so far every creator of the most popular indent-objects and their users agreed on that. This also means all users who have been using indent-plugins until now would expect such behavior since at least 2010 because thats what everybody is used to and is the default behavior in all such plugins.

But for that, there is already the the entireBuffer textobj which you can use

But than I would have to consciously think and decide which object/mapping to use instead of just letting the object doing its job which leads to the following hack:

If you really want ii to also work as entireBuffer on indention level 0, you could create a two-line-snippet using vim.fn.indent and expr to switch between ii and entireBuffer depending on the current indentation level.

Regarding the behavior of ii, ai, iI and aI maybe I will open an issue sometime in the future.

Which means so far every creator of the most popular indent-objects and their users agreed on that.

...or that no creator has cared enough about this edge case to do something about it 😉

To be honest, I disabled the indent-object at level 0 since I occasionally deleted the entire buffer on accident. But the beautify of using a customizable editor like nvim is that there is no need to argue about preferences, since everyone can customize stuff to their own liking.

If there are more users state that the indent-level-zero behavior is useful to them, I'll change the default and use a snippet myself 🙂