Skip to main content

Primary

Keymap

Loading...

Syntax

Syntax Node (Coarse).

This selection mode is powered by Tree-sitter.

This is one of my favourite selection mode, as it enable structural editing.

There are two Syntax Node selection modes:

  • Coarse: faster movement, lower accuracy
  • Fine: higher accuracy, slower movement
MovementMeaning
Left/RightNext/Previous named sibling node
Previous/NextNext/Previous sibling node, including anonymous ones
UpParent node
DownFirst named child
CurrentSelect the largest node
JumpJump to largest node

Largest Node

Using the following Javascript expression as example:

fox.bar();

There are several syntax nodes that start with f1:

  • fox (identifier)
  • fox.bar (member expression)
  • fox.bar() (call expression)

Suppose the cursor is below f, pressing s selects fox.bar(), because fox.bar() is the largest node that starts with f.

Named node

When creating a Tree sitter grammar file for a language, the author can choose to not give names to a certain kind of nodes.

For example, "," are usually unnamed ( anonymous) in most language grammars, thus it will be skipped when using the Previous/Next movement in Syntax Node.

See more at https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes.

Examples

Loading...

Syntax*

Fine Syntax Node.

MovementMeaning
Left/RightNext/Previous named sibling node
Previous/NextNext/Previous sibling node, including anonymous ones
UpParent node
ShrinkFirst child (including anonymous)
CurrentSmallest node that matches the current selection
JumpJump to smallest node

Fine Syntax Node is useful when you start to expand the selection starting from the current smallest node.

Suppose we have the following Javascript expression, and the current selection is hello, and we want to select hello.world().

hello.world().foo().bar().spam().wise();

If we press d, the whole expression will be selected1, and we will need to press k several times to shrink the selection down to hello.world().

However, if we use D instead, the selection will remain as hello, and pressing k multiple times will get us to hello.world().

Line

In this selection mode, the selection is trimmed, which means that the leading and trailing spaces of each line are not meaningful. The meaningful selection of this mode is the trimmed portion of any line (this may be empty if line is only whitespaces). The other two portions of any line are the leading whitespaces and the trailing whitespaces (includes the end of line '\n' character).

MovementMeaning
Up/Down/Previous/NextMove to all kinds of line portions
First/LastMove to the first/last line of the current file
Right/LeftMove to the trimmed portion of the line
Loading...

Line*

Full Line.

Same as Line, however, leading whitespaces and trailing whitespaces, including newline characters are also selected. And, Right/Left goes to the next empty (whitespaces only) line, this behavior is similar to move by paragraph.

Word

Each unit is a sequence of alphanumeric characters including - and _.

MovementMeaning
Up/Down/Previous/NextMove to all kinds of word, including symbols and whitespaces
Left/RightMove to non-symbol word only

Suppose the following example:

use crate::{components::editor::OpenFile, char_index::CharIndex};

If the current selection is selecting use, the following table demonstrates how many steps it takes to navigate to OpenFile.

Navigation include/exclude symbolsStepsCount
Includecrate : : { components : : editor : : OpenFile11
Excludecrate components editor OpenFile4
Loading...

Subword

This selects subword within a subword.

For example, myOatPepperBanana consists of 4 short subword, namely: my, Oat, Pepper and Banana.

This is useful for renaming identifiers, especially if we only want to change a single subword of the name. 1

MovementMeaning
Up/Down/Previous/NextMove to all kinds of subword, including symbols
Left/RightMove to non-symbol subword only
Loading...

Char

Character.

In this selection mode, the movements behave like the usual editor, where Left/Right means left/right, and so on.

First/Last means the first/last character of the current word.

Loading...

Footnotes

  1. You can try it out at https://astexplorer.net/, using the @typescript-eslint/parser. 2 3