In this chapter we have seen that bash provides command-line editing with two modes: vi and emacs . You may be wondering why these two editors were
If you are not familiar with either of these editors, you should seriously consider adopting emacs-mode keyboard habits. Because it is based on control keys and doesn't require you to think in terms of a "command mode" and "insert mode," you will find emacs-mode easier to assimilate. Although the full emacs is an extremely powerful editor, its command structure lends itself very well to small subsetting: there are several "mini-emacs" editors floating around for UNIX, MS-DOS, and other systems.
The same cannot be said for vi , because its command structure is really
Both bash editing modes have quite a few commands; you will undoubtedly develop keyboard habits that include just a few of them. If you use emacs-mode and you aren't familiar with the full emacs , here is a subset that is easy to learn yet enables you to do just about anything:
· For cursor motion around a command line, stick to CTRL-A and CTRL-E for beginning and end of line, and CTRL-F and CTRL-B for moving around.
· Delete using DEL (or whatever your "erase" key is) and CTRL-D; as with CTRL-F and CTRL-B, hold down to repeat if necessary. Use CTRL-K to erase the entire line.
· Use CTRL-P and CTRL-N (or the up and down arrow keys) to move through the command history.
· Use CTRL-R to search for a command you need to run again.
· Use TAB for filename completion.
After a few hours spent learning these keystrokes, you will