How to make [home] go to beginning of line instead of beginning of buffer?

4

1

I know there is an existing shortcut to do this but I'd like to have the home key mapped to beginning-of-line instead of beginning-of-buffer.

I tried putting this in my ~/.emacs file but it seems like it is still being overwritten somehow:

(global-set-key [kp-home]  'beginning-of-line) ; [Home]
(global-set-key [home]     'beginning-of-line) ; [Home]

On that note, if anyone knows where the default keybindings are set when using emacs on FreeBSD I might be able to modify that file if it is overriding my .emacs.

EDIT: I am using FreeBSD 8.2 and accessing it through SSH/PuTTY.

This is my full .emacs file (nothing too crazy as you can see):

(keyboard-translate ?\C-h ?\C-?)

(add-to-list 'load-path "/home/sam/programs/go/go/misc/emacs/" t)
(require 'go-mode-load)

(global-set-key [kp-home]  'beginning-of-line) ; [Home]
(global-set-key [home]     'beginning-of-line) ; [Home]

javanix

Posted 2011-06-16T16:01:24.707

Reputation: 609

This may or may not be related, but what OS are you using? You mention FreeBSD, but it's in a side note, so it's not entirely clear (at least to me) that it's the same as your main question. – Shauna – 2011-06-16T16:57:59.100

Your code seems correct. Can you try a .emacs containing just these two lines? – maxelost – 2011-06-17T12:18:34.810

Answers

3

Give this a try:

(global-set-key (kbd "<home>") 'move-beginning-of-line)

Chris Poole

Posted 2011-06-16T16:01:24.707

Reputation: 1 749

For my FreeBSD 9 system "<home>" does not work, but "<begin>" does. – goertzenator – 2011-12-22T16:07:05.913

1

I use:

(define-key global-map [home] 'beginning-of-line)

Your way seems like it should work too. Another suggestion to help you debug the problem. Hit C-h k [home] and it should show you what home is bound to and that may also give a clue what is setting it.

Ciclamino

Posted 2011-06-16T16:01:24.707

Reputation: 521

1

You can use smart home key like in: https://stackoverflow.com/questions/145291/smart-home-in-emacs/

Complete code:

(defun my-smart-beginning-of-line ()
  "Move point to beginning-of-line. If repeat command it cycle
position between `back-to-indentation' and `beginning-of-line'."
  (interactive "^")
  (if (and (eq last-command 'my-smart-beginning-of-line)
           (= (line-beginning-position) (point)))
      (back-to-indentation)
    (beginning-of-line)))

(global-set-key [home]     'my-smart-beginning-of-line)

gavenkoa

Posted 2011-06-16T16:01:24.707

Reputation: 1 386