Sunday, October 16, 2011

Tcsh history-search-forward and history-search-backward

Linux and I go way back.  From 1998 on, it has been my operating system of choice for web development, software programming, kernel and compiler toolchain hacking for embedded systems, and more recently, hardware design and verification.  For technical work, my productivity using Linux is unmatched when compared to using Windows.

There is a catch, however.  This increase in productivity is only applicable when my shell is configured how I like it.  For me, the most important option in my shell configuration are editor commands history-search-forward and history-search-backwards.  These are two options that you absolutely cannot live without, here's why...

By default, the up and down arrow keys are configured to display adjacent items in the history list.  That is, if your last command executed is 'gvim', pressing up will recall that command.  When history-search-forward and history-search-backward are enabled, the up and down keys will search your history backwards and forwards, respectively, for entries matching the current input.

Here is an example to illustrate the option's usefullness.  First, we execute gmake.  Next, we run a number of commands.  To run gmake again, type g, then press up, and gmake is copied from the history buffer.

To enable this functionality, add the following lines to your local .cshrc file and open a new terminal window.

bindkey -k down history-search-forward
bindkey -k up history-search-backward