I have several custom Bash bindings in ~/.bashrc that run actions when I press Escape followed by a letter. For example, I use Escape plus different keys to change font sizes on a virtual console, and another sequence to apply aggressive power-saving settings such as limiting the CPU to 400 MHz. These shortcuts are useful because they let me work without a desktop environment and avoid having to remember rarely used commands or search through shell history.
However, after enabling vi editing mode in Bash, the Escape-based shortcuts no longer behave as expected. Is there a way to keep these custom sequences while using vi mode? Are there better key sequences or command-based alternatives, such as functions or aliases, that would avoid conflicts with vi-style editing?
5 Answers
If you want a more complete vi-like command-line experience rather than manually maintaining many bindings, BLE.sh is worth investigating. It replaces or extends Bash's line editor and provides richer editing features while still allowing custom actions. It may be more setup than you need, but it can make Bash feel much closer to a full vi environment.
You can keep the bindings; vi mode has separate keymaps. Bind the sequence explicitly in the mode where you want it to work. For example, an Escape-L binding could be configured for both the default emacs map and vi's insert map:
bind -x '"\eL":"ls -la"'
bind -m vi-insertion -x '"\eL":"ls -la"'
The exact map names depend on the Bash version, so checking the available bindings with `bind -p` is useful. Remember that vi command mode and vi insertion mode have different key bindings.
Consider using a prefix that is less likely to collide with vi or terminal control sequences. Ctrl-Space is one possible choice, followed by a letter, and it can work well as a personal leader key:
bind -x '"\C-@a":"echo do something"'
Before choosing a sequence, inspect `bind -p` in the editing modes you use and avoid overwriting standard controls such as interrupt, end-of-file, history search, and terminal flow-control keys. Simple letters mapped to functions or aliases may also be easier to remember than multi-key Escape sequences.
Keep terminal appearance controls separate from shell editing when possible. A terminal emulator can often handle font zoom, tabs, splits, and similar actions itself, while Bash functions are better for changing system settings. If you're deliberately working on a text-only virtual console, that option may not apply, but separating the responsibilities reduces conflicts with vi mode.
For actions that are really commands, functions or aliases are usually easier to maintain than shell key macros. A function for changing brightness could validate a requested value against the allowed minimum and maximum, then write the result to the appropriate system file. That gives you a memorable command you can run from any shell without depending on a particular readline editing mode.

That seems much more straightforward for brightness and power settings. I can keep the key bindings only for actions where having an immediate shortcut is genuinely useful.