I just started with Org-mode today and noticed whenever I press C-a
on a heading, the cursor is moved all the way to the beginning of the line instead of the first character in the heading.
Like so :-
* This i|s a heading.
after pressing C-a
, the cursor moves like so :-
|* This is a heading.
I want C-a
to move the cursor like so :-
* |This is a heading.
This is pretty minor quirk, but I've bound C-a
to the below function (I don't remember where I got this from) and I'd want the behvaior of it to be consistent across all emacs modes.
(defun smarter-move-beginning-of-line (arg)
(interactive "^p")
(setq arg (or arg 1))
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(back-to-indentation)
(when (= orig-point (point))
(move-beginning-of-line 1))))
The problem with Org-mode heading is, we use asterisks to indicate heading levels ( * -> level 1, ** -> level 2, and so on,) and they HAVE to be entered as the first character on the line and all these commands which move to the beginning of the line think the indentation level is the first character of the line. The solution should be pretty simple, but sadly I haven't learned elisp as of yet. All we have to do is :-
- identify if the line is a heading or not.
- if so, ignore all the asterisks and move forward by one character
- if not, invoke the smart-beginning-of-line command I mentioned in the post.
org-beginning-of-line
. But it does the same asC-a
.