1

What I'm trying to do is have C-a and C-e take me to the beginning or ending, respectively, of the logical line, not the visual line, in org-mode (with visual-line-mode active). I see that C-a is mapped to org-beginning-of-line, which, like a lot of org-mode things, seems to be context-dependent.

Here's what I'm trying.

        (define-key org-mode-map (kbd "C-a") 'move-beginning-of-line)
        (define-key org-mode-map (kbd "C-a") 'move-end-of-line)
        

This seems to do nothing. C-h k followed by C-a still shows it's still mapped to org-beginning-of-line. I also tried using the angle bracket form of calling kbd: (kbd "<C-a>"), which made no difference.

If it helps, here's what I get when I do C-h m:

Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
Blink-Cursor Electric-Indent File-Name-Shadow Font-Lock Global-Eldoc
Global-Font-Lock Global-Visual-Line Line-Number Mac-Mouse-Wheel
Menu-Bar Show-Paren Tool-Bar Tooltip Transient-Mark Visual-Line

UPDATE: both @Tyler and @NickD solved the problem with their answers. Also it turns out the visual-line-mode-map had a remapping as well, which also needed to be unmapped. Here's specifically what I added to my .emacs file to solve the entire thing:

(add-hook 'visual-line-mode-hook
      (lambda ()
        (define-key visual-line-mode-map [remap move-beginning-of-line] nil)
        (define-key visual-line-mode-map (kbd "C-a") 'move-beginning-of-line)            
        (define-key visual-line-mode-map [remap move-end-of-line] nil)
        (define-key visual-line-mode-map (kbd "C-e") 'move-end-of-line)))

(add-hook 'org-mode-hook
      (lambda ()
        (define-key org-mode-map [remap move-beginning-of-line] nil)
        (define-key org-mode-map (kbd "C-a") 'move-beginning-of-line)            
        (define-key org-mode-map [remap move-end-of-line] nil)
        (define-key org-mode-map (kbd "C-e") 'move-end-of-line)))
2
1

Org-mode remaps move-beginning-of-line to org-beginning-of-line. Consequently, any keybinding you attach to move-beginning-of-line will call org-beginning-of-line. To undo this, you need to undo the remapping:

(define-key org-mode-map [remap move-beginning-of-line] nil)
(define-key org-mode-map (kbd "C-a") 'move-beginning-of-line)
0
0

Org mode remaps move-beginning-of-line to org-beginning-of-line using this code (in org-keys.el):

(org-remap org-mode-map
       ...
       'move-beginning-of-line 'org-beginning-of-line
       'move-end-of-line       'org-end-of-line
       ...
)

(where I have elided a bunch of other remappings).

I don't understand the mechanism well enough to provide a decent explanation (which is also a warning to take the following suggestion with a large grain of salt), but remapping them afterwards to themselves seems to work (no guarantees, if it breaks you own it, etc.):

(with-eval-after-load "org-keys"
   (org-remap org-mode-map
        'move-beginning-of-line 'move-beginning-of-line
        'move-end-of-line       'move-end-of-line))

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.