Dirk
Dirk

Reputation: 471

Rebind cursor movement in emacs

i am actually trying to customize my emacs keys for cursor movement. And what i want to archive is that when i enter M-+ or M-- that the cursor either moves to the end of line or to the beginning. And also i am trying to setup C-i for backward-paragraph and forward-paragraph. What i thought should be done with some code in my .emacs file like this:

(global-set-key (kbd "C-k") 'forward-paragraph) 
(global-set-key (kbd "C-i") 'backward-paragraph) 
(global-set-key (kbd "M-+") 'back-to-indentation) 
(global-set-key (kbd "M--") 'end-of-line)

But unfortunately none of these global keys are working. Could someone give me a hint what i am doing wrong? Thanks in advance

Upvotes: 1

Views: 477

Answers (1)

juanleon
juanleon

Reputation: 9410

An alternative way to define key-bindings is to use vector notation:

(global-set-key [(control k)] 'forward-paragraph)
(global-set-key [(control i)] 'backward-paragraph)
(global-set-key [(meta ?+)] 'back-to-indentation)
(global-set-key [(meta ?-)] 'end-of-line)

I find this way more intuitive, and I have been using it for so many years now that I already forgot the caveats of "kbd notation"

Upvotes: 4

Related Questions