Sep 09, 2021 . 2 min

Releasing evil-textobj-tree-sitter

demo of evil-textobj-tree-sitter


Hey everyone, just wanted to mention about a new package that I released recently. The package name is evil-textobj-tree-sitter and you can find it on my Github.

This package provides textobjects for evil-mode using tree-sitter. It helps add textobjects like functions, classes, loops, conditionals etc into evil-mode.

In case you are not familier with how evil-mode or vim works, let me give you a quick walkhrough of the essentials. You might have heard of vim having differnet modes or it being modal. One of those modes is normal mode. In this mode, every keystroke that you do is a command to the editor instead of a direct edit done on the text. This command structure follows a certain grammar in most cases. It usually follows <count><action><target>.

Let me give you an example. Before that let me introduce you to a few actions and targets.

There is a log more, just list a some major ones.

Now, for targets:

Once you have these, you can combine them.

You get the idea right, right?

So, now to what my plugin does. We help add more targets to this grammar. One such example would be function.inner. Let us assume that we map it to the key combo if.

Now you can do:

You see how powerful this becomes? Likewise there are other plugins which add actions as well. For example if you have added in a plugin that addes the comment action, you can ask Emacs to just comment the function without having to manually select the function boundary. Sweet, right?

All of this is powered by tree-sitter. tree-sitter at its core is a laugage parser which will give you an ast like thing that you can query on. This is just scratching the surface of what tree-sitter can do. I am hoping to play around with it more in the coming days. I already have few other tree-sitter related things in my configs which I would like to extract out and make into a plugin in the future. Btw, I owe a lot to the maintainers of nvim-treesitter-textobjects as I have copied the tree-sitter queries directly from that project.

Feel free to checkout the package if you are using Emacs :). It should be available in melpa. You can find more information in the README.

← Home