Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Textobjects

Selecting and manipulating text with textobjects

Textobjects select a whole word, paragraph, function, or other piece of text without counting characters or moving to its start. Select the object, check the highlighted text, then apply an action such as c, d, or y. Try Edit code with textobjects for exercises with words, quotes, function navigation, and scoped changes.

Textobject demo Textobject tree-sitter demo

  • ma - Select around the object (va in Vim, <alt-a> in Kakoune)
  • mi - Select inside the object (vi in Vim, <alt-i> in Kakoune)
Key after mi or maTextobject selected
wWord
WWORD
pParagraph
(, [, ', etc.Specified surround pairs
mThe closest surround pair
fFunction
tType (or Class)
aArgument/parameter
cComment
TTest
eData structure entry
gChange
sSpelling finding
x(X)HTML element

Function, type, argument, comment, test, entry, and element objects require syntax support for the language. Check the textobjects column in Language support.

The s textobject uses spell-checking findings. Both mis and mas select the diagnosed word under the cursor; mIs and mAs select every finding fully contained in the current selection. Use [s and ]s to navigate to the previous or next finding. These commands also work in plain text and scratch buffers when spell checking is enabled.

Select all objects in a region

Use mI for every inside object or mA for every around object fully contained in the current selections. For example, press %, then mIf to select the inside of every function in the buffer. Apply y, c, or another action to all of them at once.

Select-all supports words, paragraphs, the syntax objects above, Git changes, and spelling findings. mId and mAd select diagnostic ranges. Surround pairs are selected individually with mi and ma.

Navigating between functions, classes, parameters, and other elements is possible using tree-sitter and textobject queries. For example to move to the next function use ]f, to move to previous type use [t, and so on.

Tree-sitter-nav-demo

For the full reference see the unimpaired section of the key bind documentation.

💡 This feature relies on tree-sitter textobjects and requires the corresponding query file to work properly.