Enable vi ksh Command Line Editing

The Korn shell has the ability to utilize vi editor commands to edit commands in your history. If you are familiar with the vi editor, you will love this feature.


To enable vi editing, type the following command, or place it in your .kshrc file:

set -o vi

Then you can use vi commands. Press escape to enter vi command mode, and then you have access to many vi commands. For example, k will move up through previous commands in the history, /tail will search for the most recent command containing the word tail and pressing n will find the next occurence of that search term.

Once you have found a command that you want to repeat, just press ENTER, and it will be run again. You can edit the command with R to replace characters from your current position, x to delete the current character, i to insert characters before the current character, a append characters after the current character, and $ to move to the end of the command.

 

About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply

You may also like-

OS X: Easily edit hidden configuration files with TextEditOS X: Easily edit hidden configuration files with TextEditIn OS X, hidden files (those starting with a period like.profile or.bashrc) can be a challenge to edit because they are, well, hidden and ... Copy and paste text with vi or vimCopy and paste text with vi or vimThe ability to duplicate text in an editor can be handy. vi and vim have several useful copy and paste commands. The command 'Y' ...