Sunday, July 27, 2014

Enable autocompletion / autoclosing of brackets / parentheses / quotes in bash

These are my ~/.inputrc settings:

    set editing-mode vi
    set completion-ignore-case on
    set completion-map-case on
    set mark-symlinked-directories on
    set menu-complete-display-prefix on


    set keymap vi-insert
    "\C-b": backward-char
    "(": "\C-v()\C-b"
    "[": "\C-v[]\C-b"
    "{": "\C-v{}\C-b"
    "\"": "\C-v\"\C-v\"\C-b"
    "\'": "\C-v\'\C-v\'\C-b"
  

One drawback of this approach is that when you paste text into bash or ipython or any other session that makes use of readline, it will also expand your pasted text, which is definitely a disaster. To disable this behavior temporarily, I have created a Plan-B ~/.inputrc_no_auto_complete:

    set editing-mode vi
    set completion-ignore-case on
    set completion-map-case on
    set mark-symlinked-directories on
    set menu-complete-display-prefix on
  

Which does not contain autoclosing code. Whenever I want to disable autoclosing, I just type export INPUTRC=~/.inputrc_no_auto_complete into bash shell. Very handy!

0 comments: