In Emacs there are two essential commands when you have to go the
beginning of a line -
M-m). The first takes you to the
first column of a line and the latter takes you the first non-whitespace
character on a line.
Generally, I find
back-to-indentation more useful, but occasionally
it makes sense to go to the real beginning of a line as well. What
doesn’t make sense is to have to think all the time what command is
the most appropriate in a particular situation. Wouldn’t it be great
C-a initially took you to the first non-whitespace char(as
back-to-indentation does) on a line, and if pressed again took
you to the actual beginning of the line? It would be! Let’s get it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
The command will keep toggling between the first non-whitespace char and the beginning of the line when invoked.
Here’s a visual example(
| is the cursor):
1 2 3 4 5 6 7 8
This functionality could also be implemented with
defadvice, but I tend to avoid their use.
smarter-move-beginning-of-line is part of Prelude.
P.S. The credit for this tip goes to Sebastian Wiesner.