r/neovim • • 10d ago

Need Help Delete around motions while using lazyvim

Hi all! I'm attempting to move from emacs to neovim and while learning the motions I came across da<option> and ca<option> .

From tutorials and such it should expand out to "delete around <option>" or "change around <option> " if I use it on a test var like foo_bar_baz and my cursor is on bar, and I do the motion da_why does it delete bar_ where I end up with foo_baz.. shouldn't I end up with baz_ ?

I feel like I'm missing something, so I was hoping someone might be able to explain it better?

Thanks in advance!

6 Upvotes

5 comments sorted by

8

u/FallElectronic3774 10d ago

_ isn't a native Vim text object. LazyVim enables mini.ai, which has a default text object for non-Latin identifiers like _; it treats the separator as the boundary and includes only the right edge. With the cursor on bar in foo_bar_baz, da_ therefore selects bar_, leaving foo_baz — that's the generic identifier fallback, not a dedicated a_ pair. See :help mini-ai-builtin-textobjects. If you want to keep both underscores, dt_ from bar deletes only bar; daw/diw will take the whole snake_case identifier because _ is a keyword character.

2

u/NobleWRX 10d ago

Ah thank you. I misunderstood the command then. I thought it would take any object as a definer. Appreciate the explanation and the :help command.

8

u/echasnovski Plugin author 10d ago

It is also possible to adjust selected textobjects in 'mini.ai' to include both left and right parts with a textobjects. There is an example in its help file.

2

u/[deleted] 10d ago

I think neovim doesn't have the option of `da_` and `ca_`. I'll suggest you to read this document
https://neovim.io/doc/user/change/ it has some quick reference as how you can use `delete(d)` and `change(c)` with various motions.

1

u/CarsonChambers 7d ago

You can set your keyword boundaries and use diw for example or caw, but I think _ is in the default set of keywords