wiki/notebook/editor.neovim.text-objects.org
Gabriel Arazas a5b3c7a8a1 Update various notes on things
Still cannot make up a good note-taking habit especially that I archive
more than taking notes. Though, this same cannot be said for my course
notes so that's a plus.
2022-05-22 22:47:20 +08:00

1.7 KiB

Neovim text objects

(Neo)Vim has a bunch of text objects that are beyond simple boundaries other than a word (aw, aW). You can find more of them with text-objects section from Neovim help system.

Text object Description
ap A paragraph, equivalent to }.
as A sentence, equivalent to ).
ab A '( )' block.
aB A '{ }' block.
a" Content inside double-quotes (").

There is also a variation for selecting only the inner content of the previous text objects (e.g., ip for the inner paragraph, is for inner sentence) with the whitespace removed.

Note that selecting with text objects is different from selecting with roam:Neovim motions where it refers to the current position up to the end of the next selection. Meanwhile, text objects selection will select to the referred object as a whole no matter where the cursor position. For example, selecting with the paragraph (i.e., vap) will select the whole paragraph where the cursor rests.

Aside from the built-in text objects, you can create your own. Which also means others have created some custom text objects.

  • nvim-treesitter-textobjects add text objects support for selecting (and swapping, moving, and peeking) tree-sitter nodes. (Assuming you have tree-sitter support enabled for Neovim.)