Home > Emacs Tips > Emacs tip #1 – Cursor Movement

Emacs tip #1 – Cursor Movement

Why learn Emacs cursor movement keys?

  • Keep your fingers on home row for greater speed and less fatigue.
  • Enjoy richer navigation than by using built-in keyboard commands.
  • Use the bindings in a lot more places than just Emacs.

Observers may be amazed how the cursor flies around as an accomplished Emacs user is at the keyboard.  Many people aren’t aware they can move the cursor so dramatically with so little hand movement.  Non-programmer types may have no idea they can do things like move the cursor forward or backward a word at a time.

Not only will the Emacs key bindings make you quicker in Emacs, but they work in many other places.  The shell is a common place to use them.  They even work in some GUI programs.  MacOS makes pervasive use of them in stock applications.  I love using them in a web browser, for example.  Not even Linux is so thorough in its support.

There’s no point in repeating the key bindings here when they are described in so many other places.  Check this Emacs Cursor Control link for a source or search the web fore more.

You should learn the up, down, forward and back keys at a minimum.  With some practice you won’t even think about what keys to press – it will just happen.  Moving to the beginning and end of lines is also super handy.  I use a few other commands in combination with these basics as the majority of my key-strokes every day.

  • ctrl-k to delete from cursor to the end of the line.
  • ctrl-y to yank things from the cut buffer.  Think of ctrl-v if you don’t know what this is.
  • ctrl-d to delete “backwards”.
  • ctrl-o to open up a new line and push things after point down.

Some navigation keys that don’t get used as often, but that are worth mentioning, move point a word at a time.  M-f, M-b are both great commands to learn for faster navigation if you can train your mind to think of them at the right times.  Another key combination that coders may appreciate is M-m, to move point to the beginning of the current statement.  Using M-< and M-> move point to the beginning and end of the buffer, respectively.  Using ctrl-v and M-v move point a page down or up at a time.

Coders will appreciate movement keys specific to their tasks.  Emacs makes it easier to navigate “C” code, for example.  By placing the cursor on an opening brace and pressing Ctrl-M-n, point moves to the position just after the accompanying closing brace.  By placing point just after a closing brace and pressing Ctrl-M-p, the user can move point to the opening brace.  These commands are useful for navigating poorly written functions with extremely long blocks and/or deeply nested structure.

While you can continue using the arrow keys, page up/down, home, and end, learning the Emacs cursor control bindings is a fundamental building block that will serve you well.  Master Emacs key bindings and you may find yourself writing code as if spewing slugs from a Gatling Gun in full-bore.

Advertisements
Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: