9

It's easy to navigate quickly from the start of one org-mode headline to another using speed keys.

Suppose now I'm at the start of a headline, and I want to add to the main text, in the beginning immediately after the TODO keyword. Then M-f Space will get me where I want to go. If there is no TODO keyword, then it's M-f M-b.

If I want to get to the end of the headline text, it's trickier. If there are no keywords at the end, and no folded text hidden under the headline, it's as easy as C-e. But that's rarely the case. If there is folded text, but no keywords, then I can do C-e M-b. But if there is a keyword or two at the end of a folded headline, then I will find myself typing (the horror) C-e M-b M-b M-b M-f! And if there are more then two keywords, it gets worse.

When I'm jumping around and editing a lot of headlines one after the other, this can be a lot to think about and it really mess up my whole flow. Ideally I'd like to re-define s and e as speed keys to get me exactly I want to go, in all of these cases.

Has anyone seen an existing solution to this problem? My elisp skills are minimal and it would be daunting to solve this on my own.

  • 2
    If the headline is a single sentence (I think in most cases that would be true), you can M-e (i.e. move to the end of the sentence). – wvxvw Oct 19 '15 at 14:15
9

Solution

You need to set the org-special-ctrl-a/e variable to t.


Documentation

Non-nil means `C-a' and `C-e' behave specially in headlines and items.

When t, `C-a' will bring back the cursor to the beginning of the
headline text, i.e. after the stars and after a possible TODO
keyword.  In an item, this will be the position after bullet and
check-box, if any.  When the cursor is already at that position,
another `C-a' will bring it to the beginning of the line.

`C-e' will jump to the end of the headline, ignoring the presence
of tags in the headline.  A second `C-e' will then jump to the
true end of the line, after any tags.  This also means that, when
this variable is non-nil, `C-e' also will never jump beyond the
end of the heading of a folded section, i.e. not after the
ellipses.

When set to the symbol `reversed', the first `C-a' or `C-e' works
normally, going to the true line boundary first.  Only a directly
following, identical keypress will bring the cursor to the
special positions.

This may also be a cons cell where the behavior for `C-a' and
`C-e' is set separately.

Example

Below is evaluated,

(setq org-special-ctrl-a/e t)

(1) Initial state (▮ represents the point)

* TODO ab▮c                                                        :test:

(2) After first C-a

* TODO ▮abc                                                        :test:

(3) After second C-a

▮* TODO abc                                                        :test:

(4) After first C-e

* TODO abc▮                                                        :test:

(5) After second C-e

* TODO abc                                                        :test:▮

Related: Expand org-mode subtree with point after ellipsis?

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.