TextObjects adds support in jEdit for selecting text objects. Currently, those objects are words, sentences, paragraphs, quoted text, code blocks, text with common indentation, and comments.
This plugin attempts to duplicate text objects as they're supported in Vim. However, the behavior is not identical.
TextObjects provides two types of object selection: select-in-object and select-a-object. The two modes differ in how much text is selected. For example, select-in-word selects only the word's characters. select-a-word will select leading or trailing whitespace in addition to the word's characters (leading or trailing depending on the whitespace surrounding the word).
The plugin provides the opportunity to map a keyboard shortcut to each object selection, and/or to enter object input mode. Object input mode allows objects to be selected mimicking the Vim object shortcuts.
Object selection input mode is started by the TextObjects "start-input-mode" action. You can bind a shortcut to this action in the jEdit Shortcuts options pane (the command is named "Start TextObjects input mode").
Object selection mode mimics the Vim keyboard shortcuts for selecting text objects. The amount of text is selected by either 'i', for in-object, or 'a', for a-object. After the amount is entered, the object itself can be entered. The table below shows the object mappings.
Shortcut Key | Text Object |
---|---|
w | Word |
s | Sentence |
p | Paragraph |
{ or ( or [or ] or } or ) | Block - (entered character determines the type of block to select) |
" or ' or ` | Quote - (entered character determines the quote block to select) |
c | Comment |
After an object is selected, the caret is moved to the last character position in the selected text. Hitting escape will de-select and move the caret back to its original location before selection. Pressing left or up will move the caret as if it were at the start of the selection. Pressing down or right will move the caret from the caret position.
Text block shortcuts can be repeated to select the next enclosing block. For example, given the following code:
void func(boolean flag) { if (flag) { // do something } }
If the caret is on the 'd' in the comment "do something", selecting a brace block would select the text between the braces for the if. Repeating the same brace shortcut character again would then select the text between the braces for the function "func".