Jump to first non-whitespace character in line in emacs

[Origin]: http://superuser.com/questions/331221/jump-to-first-non-whitespace-character-in-line-in-emacs

I’m looking for the emacs equivalent of vi’s ^.

How can I move my cursor to the first non-whitespace character in a line?

shareimprove this question

The command is back-to-indentation, bound by default to M-m.

shareimprove this answer

This is what I picked up from a previous Stack Overflow question:

(defun smart-beginning-of-line ()
  "Move point to first non-whitespace character or beginning-of-line.

Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
  (interactive)
  (let ((oldpos (point)))
    (back-to-indentation)
    (and (= oldpos (point))
         (beginning-of-line))))
(global-set-key [home] 'smart-beginning-of-line)
(global-set-key "\C-a" 'smart-beginning-of-line)
shareimprove this answer
Advertisements

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