Playing with Bash keyboard shortcuts

Today I’ll share about how to use keyboard shortcuts in Linux Bash to make it more convenient for all of us. Go to your home directory(~) which is usually located under “/home/{UserName}/” and open the file “.inputrc”. You should create one if it doesn’t exists. This file is used by bash typing library to provide key-bindings or features like auto complete etc.

The schema of the file is really simple and you can reach the full content here http://www.gnu.org/software/bash/manual/bashref.html#Bindable-Readline-Commands

You can do two things inside this file:

  • Set predefined variables to turn them on or off. Ex. : “set show-all-if-ambiguous on”
  • Bind keys to methods: “TAB: menu-complete”

Tricky part about escape keys are you can define¬†them by name or via escape character sequence(http://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting). For example you can set “ctrl + v” combination with “\C-v” where “\C” is the control key “-” means while pressing it and “v” is key v.

Now let’s start playing with it:

  1. In order to have auto complete upon pressing “Tab” key and moving backward upon pressing “Shift + Tab”, insert the text below to the .inputrc file:
  2. In order to remove the current line upon pressing “Escape” :
  3. In order to be able to jump between words with “Ctrl +¬†Left Arrow” or “Ctrl + Right Arrow”
  4. In order to paste the text from clipboard (Yes in Linux world you’ll hear killing for cutting and yanking for pasting operations):
  5. Sometimes playing with .inputrc file can mess up the bash for arrow, home and end keys. If that happens you can set them explicitly by:
  6. Some additional useful methods can be found at:

One Response to “Playing with Bash keyboard shortcuts”

  1. Charlie says:

    You can use the linux bash in windows! https://cygwin.com/install.html

Leave a Reply

Your email address will not be published. Required fields are marked *