简体   繁体   中英

Set custom basic shortcut in a Bash shell

I'm currently trying to optimize or learn the keybindings of the applications I use the most, in a simple and ergonomic way. Inspired by Ergoemacs keybindings, I would like to rebind some very basics commands for use in Bash as for example:

  • Ctrl + i / k / j / l : up/down/left/right
  • Ctrl + u / o : backward/forward word
  • Ctrl + d / f : delete left/right
  • Ctrl + e / r : delete word left/right
  • Ctrl + Alt + e / r : delete to begining/end of line
  • Ctrl + c / x / v : copy/cut/paste
  • etc

I've seen ways to bind custom complex commands. I've found nowhere how to do this. In windows I used to do it system wide with autohotkeys but I'm now with a linux system and no autohotkey alternative works well for me.

How can I set those key bindings for my Bash terminal?

Bash key-bindings configuration

  • For all above combinations, except the last one Ctrl + c / x / v ...

You are looking for readline ( documentation ) library settings. In Linux, programs that offer some kind of command line interface (eg bash interactive shell, octave interactive shell, python interactive shell etc.) use readline library to customize key-bindings.

Key-bindings are usually added in .inputrc configuration file in user's home directory. Here is an example of .inputrc configuration file.

Terminal emulator (eg gnome-terminal ) key-bindings configuration

  • For the last one Ctrl + c / x / v ...

In menubar of terminal emulator: Edit > Keyboard shortcuts .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM