BASH Command-Line Editing

June 26, 2007 |

If you work on command-line often, then this reference guide is for you. This is a quick reference of Emacs and Vi while in command-line bash. To enable command-line editing for vi is set -o vi and for emacs it is set -o emacs.

Emacs Editing Mode

  • CTRL-B - Move backward one character (without deleting)
  • CTRL-F - Move forward one character
  • DEL - Delete on character backward
  • CTRL-D - Delete on character forward
  • ESC-B - Move one word backward
  • ESC-F - Move one word forward
  • ESC-DEL - Kill one word backward
  • ESC-CTRL-H - Kill one word backward
  • ESC-D - Kill one word forward
  • CTRL-Y - Retrieve (”yank”) last item killed
  • CTRL-A - Move to beginning of line
  • CTRL-E - Move to end of line
  • CTRL-K - Kill forward to end of line
  • TAB - Attempt to perform general completion of the text
  • ESC-? - List the possible completions
  • ESC-/ - Attempt filename completion
  • CTRL-X / - List the possible filename completions
  • ESC- ~ - Attempt username completion
  • CTRL-X ~ - List the possible variable completions
  • ESC-$ - Attempt variable completion
  • CTRL-X $ - List the possible variable completions
  • ESC-@ - Attempt hostname completion
  • CTRL-X @ - List the possible hostname completion
  • ESC-! - Attempt command completion
  • CTRL-X ! - List the possible command completions
  • ESC-TAB - Attempt completion from previous commands in the history list
  • CTRL-J - Same as RETURN
  • CTRL-L - Clears the screen
  • CTRL-M - Same as RETURN
  • CTRL-O - Same as RETURN, then display next line in command history
  • CTRL-T - Transpose two chracters on either side of point and move point forward by one
  • CTRL-U - Kills the line from the beginning to point
  • CTRL-V - Quoted insert
  • CTRL-[ - Same as ESC
  • ESC-C - Capitalize word after point
  • ESC-U - Change word after point to all capital letters
  • ESC-L - Change word after point to all lowercase letters
  • ESC-. - Insert last word in previous command line after point
  • ESC-_ - Same as ESC.

Vi Editing Mode

  • DEL - Delete previous character
  • CTRL-W - Erase previous word
  • CTRL-V - Quote the next character
  • ESC - Enter control mode
  • h - Move left one character
  • l - Move right one character
  • w - Move right one word
  • b - Move left one word
  • W - Move to beginning of next non-blank word
  • B - Move to beginning of preceding non-blank word
  • e - Move to end of current word
  • E - Move to end of current non-blank word
  • O -Move to beginning of line
  • ^ - Move to first non-blank character in line
  • $ - Move to end of line
  • i - Text inserted before current character (insert)
  • a - Text inserted after current character (append)
  • I - Text inserted at beginning ofline
  • A - Text inserted at end of line
  • R - Text overwrites existing text
  • dh - Delete one character backwards
  • dl - Delete on character forwards
  • db - Delete one word backwards
  • dw -Delete one word forwards
  • dB - Delete one non-blank word backwards
  • dW - Delete one non-blank word forwards
  • d$ - Delete to end of line
  • d0 - Delete to beginning of line
  • k or - - Move backward one line
  • j or + - Move forward one line
  • G - Move to line given by repeat count
  • /string - Search backward for string
  • ?string - Search forward for string
  • n - Repeat search in some direction as previous
  • N - Repeat search in opposite direction of previous

These examples were taken from O’reilly bash book. It’s one of my favorite book and you can purchase it on amazon. It’s the best book available for scripting in bash in my opinion.



Comments

1 Comment so far

  1. Caio Felipe on July 19, 2007 3:55 pm

    Hey man, very nice tip! :D

    I’ve never found this info anywhere…
    BTW, the book you took the example, is it the “Learning the bash Shell, Second Edition”?

    Thanks! :D

Name

Email

Website

Speak your mind

  • Categories

  • Sponsors