Differences between revisions 2 and 3
Revision 2 as of 2010-07-27 21:01:32
Size: 2382
Editor: GreyCat
Comment: category
Revision 3 as of 2013-07-15 13:16:33
Size: 2325
Editor: static-173-71-130-68
Comment: Formatting
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Modifying the Bash Shell with the set Command == Emacs and Vi modes in Bash ==
Line 5: Line 5:
 * '''Set Emacs Mode in Bash''' === Emacs Mode ===
Line 7: Line 7:
 *  $ set -o emacs
 * $ set -o emacs
Line 12: Line 11:
 * . Commands to take advantage of bash's Emacs Mode:  * Commands to take advantage of bash's Emacs Mode:
Line 24: Line 23:
  . . '''Set Vi Mode in Bash '''
  . . $ set -o vi
  . . o Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you into command mode.
Line 28: Line 24:
 * . Commands to take advantage of bash's Vi Mode:
=== Vi Mode ===

 * $ set -o vi

 * Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you into command mode.

 * Commands to take advantage of bash's Vi Mode:

Emacs and Vi modes in Bash

Two options that can be set using the set command that will be of some interest to the common user are "-o vi" and "-o emacs". As with all of the environment modifying commands these can be typed at the command prompt or inserted into the appropriate file mentioned above.

Emacs Mode

  • $ set -o emacs
  • This is usually the default editing mode when in the bash environment and means that you are able to use commands like those in Emacs (defined in the Readline library) to move the cursor, cut and paste text, or undo editing.
  • Commands to take advantage of bash's Emacs Mode:
    • o ctrl-a Move cursor to beginning of line
    • o ctrl-e Move cursor to end of line
    • o meta-b Move cursor back one word
    • o meta-f Move cursor forward one word
    • o ctrl-w Cut the last word
    • o ctrl-u Cut everything before the cursor
    • o ctrl-k Cut everything after the cursor
    • o ctrl-y Paste the last thing to be cut
    • o ctrl-_ Undo
    • o NOTE: ctrl- = hold control, meta- = hold meta (where meta is usually the alt or escape key).
    • o A combination of ctrl-u to cut the line combined with ctrl-y can be very helpful. If you are in middle of typing a command and need to return to the prompt to retrieve more information you can use ctrl-u to save what you have typed in and after you retrieve the needed information ctrl-y will recover what was cut.

Vi Mode

  • $ set -o vi
  • Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you into command mode.
  • Commands to take advantage of bash's Vi Mode:
    • o h Move cursor left
    • o l Move cursor right
    • o A Move cursor to end of line and put in insert mode
    • o 0 (zero) Move cursor to beginning of line (doesn't put in insert mode)
    • o i Put into insert mode at current position
    • o a Put into insert mode after current position
    • o dd Delete line (saved for pasting)
    • o D Delete text after current cursor position (saved for pasting)
    • o p Paste text that was deleted
    • o j Move up through history commands
    • o k Move down through history commands
    • o u Undo


CategoryShell

set-o-vi-emacs (last edited 2022-01-19 04:01:49 by emanuele6)