I like the MATLAB way of input command — it has the same tab-complete feature; in addition, it has a up-arrow-auto-complete-history-command feature. For example, if I have typed a command “x=39;y=23;” before, now I can just type “x” and then type the up arrow button, then this command would auto-complete. It can also switch between all the history commands that has the same starting letters.
Vert unfortunately, I haven’t found any similar feature in the Linux terminal, or say bash. There is a command called “history” that can list all the history commands. I can type “history | grep xxx” to search the command I want to find. The same example, I can type “history | grep x=” try to find that command. There would come up something like “201 x=39;y=23;“. The number in the beginning is the index of in the history. Then I can type “!201″ to repeat this command. But I find this quite time-consuming.
Then I came across a shortcut of bash “Ctrl + R“, it can “search through previously used commands”. Say in the terminal I type “Ctrl + R”, then “(reverse-i-search):” came up, then I can type keyword of my previous command, say “x=” then the most related command would come up. After the right command comes up, then type enter, finish. Although not as convinient as the MATLAB mode, this is way better than using “history” command, in my view.
January 20, 2007 at 8:41 am
Excellent! I’ve been looking for something like this for a while. Thanks!
January 23, 2007 at 10:05 pm
Neat, thanks
January 23, 2007 at 10:23 pm
Second thought : I’ve posted your tip in French, linking to your blog page. I hope it’s okay with you
http://bapoumba.free.fr/?p=78
January 24, 2007 at 8:46 am
To bapoumba: That’s totally ok, I am pleased to share with others. In addition, I did not invent this, I just read this from somewhere else
. Thanks for sharing this.
April 28, 2007 at 3:31 pm
Well if you will not miss job control, you can use ipython, which is an awesome python shell, that has a shell like environment (to start it use ipython -p pysh). You can then have the exact matlab feature you want.
Suppose I have done a search like,
fine . -name ‘*.tex’
Then the next time I want to use it I simply type
find
it will even cycle through all previous find commands, etc.
(Combine this program with numpy and you also have a basic matlab replacement
May 5, 2007 at 6:45 am
This ipython is quite nice! thanks
November 6, 2007 at 6:39 pm
Something even better (and actually what you want).
Go to /etc/inputrc and find the line with history search and page-up/down, and uncomment it.
Voila history search with Page-Up/Down from the letter in front of the cursor.
February 15, 2008 at 9:29 am
Thanks! Great advice!
March 13, 2008 at 9:41 pm
Hey,
The way to do this “like MATLAB” is by adding the following lines in your .bash_profile or .bashrc file (and subsequently running source .bashrc, etc):
bind ‘”\M-[A”: history-search-backward’
bind ‘”\M-[B”: history-search-forward’
These are the keybindings I use for bash 3.2 on Mac OS X, so you might have to find other keybindings specific to your machine, but the general syntax is there! Enjoy!
March 24, 2008 at 3:21 pm
Many thanks!
June 18, 2009 at 8:20 pm
Thanks a lot!!!
October 16, 2009 at 3:01 am
Another tip:
Pressing Ctl+R again while searching will skip the latest command that is found and go on to the next one.
November 4, 2009 at 10:33 pm
Thanks a lot!!!