Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
Terminal: Beyond Ctrl + A and Ctrl + E

Update: I had some of the Ctrl and Option commands switched. Fixed now.

As Rails developers, we spend most of our day in two places: an IDE/text editor and the command line. While we spend much time learning shortcuts that help us write and refactor our source code more quickly, many of us are perfectly okay just learning Ctrl + A and Ctrl + E and holding down the arrow keys to place the cursor where we want to get to on the command line.

Don’t do that. With only a handful of additional commands, your day to day interaction with the terminal can be much more pleasant. Here are a few ways to do that using terminal and the bash shell.

A Command Line Editing Starter Pack

Here’s a quick list of commands that you’ll get a lot of day to day usage from, if you aren’t already:

  • Ctrl + A: Move cursor to the beginning of the line
  • Ctrl + E: Move cursor to the end of the line
  • Ctrl + K: Delete from cursor to the end of the line
  • Option + F: Move cursor one word forward
  • Option + B: Move cursor one word backward
  • Option + D: Delete next word
  • Option + Delete: Delete previous word

Note: You’ll need to set your meta key to Option before the commands that use Option will work (see below).

These seven simple commands will help you move more nimbly when editing text on the commands line. There is certainly plenty more you can do, which you can find in the bash manual.

A Word on Modes

By default, the bash shell run in emacs mode. This means that emacs shortcuts are enabled by default.

Emacs mode uses a Meta key for some commands, and the Option key is a good choice. In Terminal on OS X, you’ll need to enable this by going to Preferences > Settings > Keyboard and checking “Use option as meta key.”

You can also tell bash you want to use vi mode for command line editing with set -o vi, if for some reason you want to type i before every cd or ls you write.


Nothing new or overwhelmingly exciting here, and there is certainly much more to dive into if you are so inclined. However, this small set of commands will have you covered for the majority of your day to day command line editing needs and is what I would consider constitutes a minimum level of proficiency.

Give your arrow keys a break!

  • You can make home/end keys work on osx terminal, and get rid of this ctrl+e/a annoyance :)

  • Ctrl+F/B move by character on my system.

    The best part of learning these keystrokes is that they’re not Terminal-specific. You can use them practically anywhere in OS X.

  • Hunter Gillane

    @mark I accidentally had Ctrl instead Option for those. Fixed now. Thanks!

  • When using set -o vi, the command prompt by default is in text entry mode, to enter command mode, hit Esc like you would in vi. For example, you can just type cd or ls without first typing i.

  • One more useful key: Ctrl + D deletes the character after the cursor. Again, I probably use these keystrokes in Gmail more than any place.

  • Jason B.

    Is this what they are teaching you out in Boulder? Thanks for the tips mang!

  • Whiney Winnie

    the vi option for bash to use readline vi mode does of course leave the user in insert mode as the default mode, with the option the press {esc}, but it still have all the keys from vi insert mode, like ^K to delete from cursor position to end of line. Worth noting is with emacs mode (the default) ^U doesn’t represent the “universal modifier” from emacs, but “delete from cursor to start of line” (compare with ^K)

  • Anon

    Ctrl + T: Transpose – swap the current and the next character around (handy for fixing typos).

Share This