Friday, March 21, 2014

Enable vi mode editing in python, irb (ruby) and others

Everyone who uses Unix/Linux, will at one point or another, choose their editor of choice.  It is either out of necessity or, as in my case, all of the people using the system(s) around you used the same editor. 

There are several different editors, but the two most popular are emacs and vi.  I have recently started learning emacs, as I am in a group where most already use emacs.  No, I am not being pressured, I am just actually getting to experience some of the cool aspects of the editor other than someone standing around ranting that "emacs is cool!" over and over. 

Overall though, I am still very much a vi person.... no question.  If I do make the switch to emacs at some point, it will be wholely.  But for the mean time, until my comfort level is up, I am sticking with what I know best. 

That said, when I am in things like the python shell, I think having the ability to have a 'vi mode', is something beneficial to me.  I stumbled on a quick setup with will allow you to have the 'vi mode' in most, if not all, of your different shells (python, irb, etc).

What you need to do is create in your home directory, a file called .inputrc.  In the file, put the following lines:

    set -o vi
    set editing-mode vi

You don't need to source it, just simply start up something like irb or the python shell and then, when in there, hit the ESC key and you'll be in vi mode.  Nice, huh?  Enjoy!

No comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.