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?

migrated from stackoverflow.com Sep 2 '11 at 18:54

This question came from our site for professional and enthusiast programmers.


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


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."
  (let ((oldpos (point)))
    (and (= oldpos (point))
(global-set-key [home] 'smart-beginning-of-line)
(global-set-key "\C-a" 'smart-beginning-of-line)
  • this is not what the user asked for; ^ in vim does not do this; M-m is exactly the analog of ^ in vim and hence exactly the right answer. – xdavidliu Jun 27 at 3:16

You can install crux

type C-a to switch cursor between beginning of line and the first non-whitespace character

  • the question did not ask for toggling between first non-whitespace character and first column, it just asked for the analog of ^ in vim, which is exactly M-m. – xdavidliu Jun 27 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.