I use text objects with evil like "i(" for the contents of the brackets. I would quite like "magic code aware text objects"?

This textobject would:

  • return the entire function if I was at a function
  • return the entire class if I was at a class
  • return the switch if I was at an "if/elif" block


Is there a way to do this task that does not consist of completely implementing it myself?

1 Answer 1


May be https://github.com/meain/evil-textobj-tree-sitter can fit your need.

Take a look at Doom Emacs' tree-sitter module config for examples.

But if you need something so DWIMmy instead of vi's preferred explicit approach, IMO tree-sitter & expand-region : tree-sitter-mark-bigger-node should be more appropriate for you.

  • 1
    That very much looks like what I am after thanks.
    – Att Righ
    Nov 3, 2022 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.