Edit Modes

Æsh Readline supports two main editing modes: Emacs and Vi.

EditMode

import org.aesh.readline.editing.EditMode;
import org.aesh.readline.editing.EditModeBuilder;

// Create default edit mode (Emacs)
EditMode editMode = EditModeBuilder.builder().create();

// Create Vi mode
EditMode viMode = EditModeBuilder.builder()
        .mode(EditMode.Mode.VI)
        .create();

Emacs Mode

Default mode with Emacs-style key bindings.

Setting Emacs Mode

import org.aesh.readline.ReadlineBuilder;

Readline readline = ReadlineBuilder.builder()
        .editMode(EditModeBuilder.builder()
                .mode(EditMode.Mode.EMACS)
                .create())
        .build();

Emacs Key Bindings

KeyAction
C-b or Move back one character
C-f or Move forward one character
BackspaceDelete character left of cursor
C-dDelete character at cursor
C-_ or C-x C-uUndo
C-a or HomeMove to start of line
C-e or EndMove to end of line
M-fMove forward one word
M-bMove backward one word
Previous history
Next history
C-lClear screen, redraw line
M-dDelete next word
C-kKill to end of line
C-wKill to previous whitespace
C-yYank (paste)
C-rSearch backward in history
C-sSearch forward in history
M-C-jSwitch to Vi mode
TabComplete

Vi Mode

Vi-style editing with command and insert modes.

Setting Vi Mode

import org.aesh.readline.ReadlineBuilder;

Readline readline = ReadlineBuilder.builder()
        .editMode(EditModeBuilder.builder()
                .mode(EditMode.Mode.VI)
                .create())
        .build();

Vi Command Mode

KeyAction
hMove back one character
lMove forward one character
XDelete character left of cursor
xDelete character at cursor
uUndo
0Move to start of line
$Move to end of line
wMove forward one word
bMove backward one word
k or Previous line
n or Next line
C-lClear screen
dwDelete next word
D or d$Kill to end of line
dbKill to previous whitespace
pYank after cursor
PYank before cursor
y + movementAdd text to yank buffer
cEnable change mode
.Repeat previous action

Vi Edit Mode

KeyAction
C-rSearch backward in history
C-sSearch forward in history
BackspaceDelete character left of cursor
EscReturn to command mode

Switching Modes

Users can switch between modes at runtime:

  • In Emacs mode: Press M-C-j (Alt+Ctrl+j) to switch to Vi mode
  • In Vi mode: Press Esc to exit to command mode, then type editing commands

Runtime Properties

Set edit mode via system property:

System.setProperty("aesh.editmode", "VI");
// Or
System.setProperty("aesh.editmode", "EMACS");