edlin

edlin

edlin
Line and input interpretter for the erlang shell.
Module edlin was introduced in OTP 26.1.

This module reads input, handles any escape sequences that have been configured via edlin_key and outputs action requests. The action requests are handled either by modules group or the user_drv.

You can setup a custom key configuration that overrides the default key configuration. This is done by setting the stdlib application parameter shell_keymap before Erlang is started. If you want to have the same keymap in all Erlang shells you can do so by putting a config file in your user's home directory and then set ERL_FLAGS to load it at startup. For example:

$ cat $HOME/.erlang_keymap.config
[{stdlib,
  [{shell_keymap,
    #{ normal => #{ "\^[A" => clear } }
  }]
}].
$ ERL_FLAGS="-config $HOME/.erlang_keymap" erl

The current keymap configuration can be fetched through edlin:keymap(). If a custom keymap or keymap file is specified, then it will be merged with the default keymap.

The keymap is a map of maps where the keys in the parent map corresponds to different editing modes in the shell. The valid modes currently supported are normal and search.

The keys in the child maps are the escape sequences that are sent from the terminal when a key is pressed and each value is a valid action as seen below.

The default atom is used to specify that an action should happen when a key is pressed that does not have any mapping. Typically used to exit a mode.

See tty - A Command-Line Interface for more information about the default keymap.

The commands below are the built-in action requests for switching input modes on the normal shell or navigating, or manipulating the line feed. The line feed supports multiple lines.

Automatically close the closest matching opening parenthesis.

Move backward one character.

Delete the character behind the cursor.

Delete the word behind the cursor.

Delete all characters from the cursor to the beginning of the line and save them in the kill buffer.

Delete the word behind the cursor and save it in the kill buffer.

Move backward one line.

Move backward one word.

Move to the beginning of the expression.

Move to the beginning of the line.

Clear the screen.

Clear the current expression.

Move to the end of the expression.

Move to the end of the line.

Move forward one character.

Delete the character under the cursor.

Move forward one line.

Move forward one word.

Move to the next item in the history.

Move to the previous item in the history.

Delete all characters from the cursor to the end of the line and save them in the kill buffer.

Delete the word under the cursor and save it in the kill buffer.

Add a newline at the end of the line and try to evaluate the current expression.

Add a newline at the cursor position.

Open the current line in an editor e.g. EDITOR="code -w" opens a buffer in vs code. Note that you need to pass a flag to the editor so that it signals the shell when you close the buffer.

Redraw the current line.

Cancel the current search.

Accept the current search result and submit it.

Accept the current search result, but edit it before submitting.

Enter search mode, search the history.

Skip to the next line in the history that matches the current search expression.

Skip to the previous line in the history that matches the current search expression.

Output all possible tab completions.

Go back to normal mode.

Autocomplete the current word, or show 5 lines of possible completions.

Swap the character behind the cursor with the one in front of it.

Swap the word behind the cursor with the one in front of it.

Insert the contents of the kill buffer at the cursor position.

Types

keymap() = #{atom() => #{string() | default => atom()}}

Get the current keymap used in the shell. Each key in the parent map represents a shell mode e.g. normal or search. Each map associated with the shell modes contains key sequences represented as strings, paired with an action, which is one of the valid actions mentioned above.