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

Line Editing

Hash shell includes a custom line editor with full cursor navigation and editing capabilities.

Key Bindings

Cursor Movement

KeyAction
Left ArrowMove cursor left
Right ArrowMove cursor right
Up ArrowPrevious command in history
Down ArrowNext command in history
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
HomeMove to beginning of line
EndMove to end of line

Editing

KeyAction
BackspaceDelete character before cursor
DeleteDelete character at cursor
Ctrl+HSame as Backspace
Ctrl+UDelete from cursor to beginning
Ctrl+KDelete from cursor to end
Ctrl+WDelete word backward

Other

KeyAction
TabAuto-complete
Ctrl+LClear screen
Ctrl+CCancel current line
Ctrl+DEOF (exit if line empty)
Enter or Ctrl+JSubmit command

Features

Insert Mode

Hash uses insert mode (like bash):

  • Typing inserts characters at cursor position
  • Existing text shifts right
  • Edit anywhere in the line
hello world
     ^
     cursor

Type 'beautiful ' → hello beautiful world

Typing Ahead

Text typed while a command is still running is not lost. The terminal echoes it once as you type it, and when the prompt comes back the editor reads it and runs it, so you can queue the next command without waiting:

#> sleep 2
echo next          # typed during the sleep
#> echo next       # the editor shows it again, then runs it
next

Keys typed between pressing Enter and the command’s first read go to the command, as they do in other shells.

Tab Completion

Press TAB to auto-complete:

Single match:

#> ec<TAB>
#> echo   # Completed with space

Multiple matches - first TAB:

#> cat te<TAB>
#> cat test  # Common prefix

Multiple matches - second TAB:

test.txt  test.md  testing.log
#> cat test

See Tab Completion for details.

Ctrl+C Handling

Cancel current input and get a fresh prompt:

#> some long command^C
#>

Ctrl+D Behavior

  • On empty line: Exits the shell
  • On non-empty line: Does nothing

Vi Mode

set -o vi switches the editor to vi’s modal editing; set -o emacs (the default) switches back. Both appear in set -o, and set +o prints the one in effect as a command you can put in ~/.hashrc.

Each line starts in insert mode, where every key works as in emacs mode. Esc enters command mode: the cursor stands on a character, motions move it, operators act on a motion, and i, a, I, A return to inserting. Words are blank-separated. Counts are not implemented.

KeyAction
EscCommand mode
h l (or arrows)Left, right
0 ^ $Start, start, end of line
w b eNext word, previous word, end of word
i a I AInsert here, after the cursor, at the start, at the end
x XDelete the character under, before the cursor
d + motion, dd, DDelete through a motion, the whole line, to the end
c + motion, cc, C, s, SDelete the same, then insert (cw changes to the end of the word)
y + motion, yyCopy to the cut buffer
p PPut the cut buffer after, before the cursor
r + charReplace the character under the cursor
~Toggle case and move right
uUndo the last edit (again redoes)
k j (or arrows)Older, newer history entry, cursor at the start
/Incremental history search: type, Enter runs the match, Esc keeps it for editing
EnterRun the line, from either mode
#> set -o vi
#> echo helo          # Esc, h, i, l, Esc, Enter
hello

Tips & Tricks

Quick Edits

# Typed wrong command
#> cat file.tx
# Press Ctrl+A, Ctrl+K, type correct command

Delete Mistakes

#> echo hello worldddd
# Press Ctrl+W to delete "worldddd"
#> echo hello

Clear and Restart

#> some complex command
# Press Ctrl+U to clear
#>

Cancel Without Running

#> rm -rf /important
# Press Ctrl+C
^C
#>

Troubleshooting

Keys Not Working

Check terminal type:

echo $TERM
# Should be xterm, xterm-256color, etc.

Arrow Keys Print Escape Sequences

Set proper terminal:

export TERM=xterm-256color

Comparison with Bash

Supported (Same as Bash)

  • Arrow key navigation
  • History navigation
  • Ctrl+A, Ctrl+E
  • Ctrl+U, Ctrl+K, Ctrl+W
  • Ctrl+L, Ctrl+C, Ctrl+D
  • Home/End keys
  • Insert mode
  • Ctrl+R reverse search
  • Vi mode (set -o vi), the subset listed above

Not Yet Supported

  • Ctrl+T (transpose)
  • Alt key bindings
  • Vi counts and text objects
  • Custom key bindings