Ever get tired of typing long directory or file names and wish there were a simple keystroke to finish the word you’re entering? The solution lies in the line editor. The line editor allows you to get a previous command, finish a file or directory name, or list files by typing only a few characters. There are many line editors you can choose to use, however. Below is a simple table that compares two of them—VI and EMACS—and presents some of the commands associated with each.
Use EMACS instead of VI
Usually the default line editor is VI, but I personally prefer EMACS. It is possible to make your system automatically use EMACS by changing the .kshrc or .profile files, but that is beyond the scope of this article. The simplest way to switch to EMACS (if you choose to do so) is to type the following line in your terminal window:
set –o emacs
Note that it is set, dash the letter o and not set, dash zero.
Line editor commands
Below is a table of line editor commands you can use while you are working in a terminal window.
|VI Command||EMACS Command||Meaning|
|#k or #–||CTRL–p||Gets previous command from history|
|#j or #+||CTRL–n||Gets next command from history|
Completes pathname of the current word;
appends a backslash (\) to the end of
directories and a space to files
Lists files that begin with the current word
and returns to the current line status
|#h||CTRL–b||Moves cursor one character to the left|
|#l||CTRL–f||Moves cursor one character to the right|
|#b||ESC b||Moves cursor left one word|
|#w||ESC f||Moves cursor right one word|
|0||CTRL–a||Moves cursor to the start of line|
|$||CTRL–e||Moves cursor to the end of line|
Enters input mode to input at current
point/Enters append mode to enter
after current point
|#x/#X||CTRL–d/CTRL–h||Deletes current/previous character|
|d#w/d#W||ESC d/ESC CTRL–?||Deletes current/previous word|
Note: In VI, ESC enters command mode and exits after editing, while # stands for any
Hopefully, having these commands at your fingertips will help increase your productivity and ease your workload.
What do you think of Mike’s line editor commands? What other UNIX tips and tricks would you like to see? Post a comment or write to Mike Hayes and let us know.