Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Terminal: Beyond Ctrl + A and Ctrl + E

Hunter Gillane
Saturday, November 12, 2011

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.

End

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!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

6 Comments

  1. grosser says:

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

    http://tech.inhelsinki.nl/gnu_developement_under_mac_os_x/

    November 12, 2011 at 6:29 pm

  2. Mark Wilden says:

    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.

    November 12, 2011 at 7:36 pm

  3. Hunter Gillane says:

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

    November 12, 2011 at 7:57 pm

  4. Jason Noble says:

    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.

    November 12, 2011 at 8:44 pm

  5. Mark Wilden says:

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

    November 13, 2011 at 4:38 pm

  6. Jason B. says:

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

    November 18, 2011 at 3:44 pm

Add New Comment Cancel reply

Your email address will not be published.

Hunter Gillane

Hunter Gillane
Boulder

Recent Posts

  • Boulder Standup – Feb 24, 2012
Subscribe to Hunter's Feed

Author Topics

terminal (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >