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:
- 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:
12345set show-all-if-ambiguous onset completion-ignore-case onset match-hidden-files onTAB: menu-complete"\e[Z": "\e-1\C-i" - In order to remove the current line upon pressing “Escape” :
1"\e": kill-whole-line - In order to be able to jump between words with “Ctrl + Left Arrow” or “Ctrl + Right Arrow”
12"\eOC": forward-word"\eOD": backward-word - In order to paste the text from clipboard (Yes in Linux world you’ll hear killing for cutting and yanking for pasting operations):
1"\C-v": yank - 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:
12345678"\e[1~": beginning-of-line"\e[4~": end-of-line"\e[7~": beginning-of-line"\e[8~": end-of-line"\eOH": beginning-of-line"\eOF": end-of-line"\e[H": beginning-of-line"\e[F": end-of-line - Some additional useful methods can be found at:
123456<a href="http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Moving" target="_blank">Commands for moving the cursor</a><a href="http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-History" target="_blank">Commands for manipulating the history</a><a href="http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Text" target="_blank">Commands For Changing Text</a><a href="http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Killing" target="_blank">Killing And Yanking</a><a href="http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Completion" target="_blank">Commands for completition</a><a href="http://www.gnu.org/software/bash/manual/bashref.html#Miscellaneous-Commands" target="_blank">Some Miscellaneous Commands</a>
You can use the linux bash in windows! https://cygwin.com/install.html