views:

40

answers:

1

I'm trying to learn emacs, getting vi custom key bindings.

Using Viper-mode, what is the correct way to re-bind a key? (I'm using Colemak keyboard layout(instead of qwerty) so have to change things like n->j) But would like it to work in viper-mode.

From this key binding guide on GNU.org: http://www.gnu.org/software/emacs/manual/html_node/viper/Key-Bindings.html

It says the command to put in your .viper file is:

(define-key viper-vi-global-user-map "\C-v" 'scroll-down)

It doesn't work for me... in fact not sure I even have the function "define-key"...

M-x define-key [No match]

I'm not sure if 'define-key' is available on my version of emacs?

This works, but not in viper-mode

(global-set-key "n" "j")

Any help would be much appreciated. This is my first day using Emacs, to it's a pain getting Colemak & Viper-mode to work properly.

Thank for any help...

+2  A: 

Hopefully some useful answers here:

First, having that line in the .viper works for me. Note that the viper-vi-global-user-map applies when you're in command mode, not insert mode.

Secondly, define-key isn't a command, it's a regular function, which just means that it cannot be called using M-x. See this Emacs wiki page for a little more detail on that distinction. But that was a good attempt.

Third, the global-set-key is a command, you could have tried making a change using M-x global-set-key. But, that sets the key in the current global map, which isn't the same as viper-vi-global-user-map. Viper-mode uses a bunch of different keymaps to make Emacs behave like vi, but all of the maps are overlaid on top of the global map.

I'm guessing that you found that C-v wasn't bound like you want when you're in insert mode. And that can be solved by adding this to your .viper:

(define-key viper-insert-global-user-map "\C-v" 'scroll-down)

Lastly, scroll-down may not be what you want. The down refers to the text moving down (given the perspective of a fixed window). C-v is generally bound to 'scroll-up. But,maybe it is exactly what you want.

Caveat: I'm not a viper-mode user, I don't even know how to use vi. So my terminology may be off. But I find the challenge of changing things in viper-mode very interesting.

Edited to add

From your comment it sounds like you want n to be the same as what j is bound to by default. Try adding this:

(define-key viper-vi-global-user-map "n" 'viper-next-line)

In "normal" mode I did M-x describe-key j, which told me that j is bound to 'viper-next-line, and the above line will bind n to the same routine. Repeat for the rest of the bindings you want to shift around.

Trey Jackson
Hey Trey, thanks for the detailed response. :) When you said "command mode" do you mean the opposite of insert mode? Vim calls this normal mode. Actually I wanted it to work in normal-mode (movement-mode)?
Quang
I should of had a more realistic 'define-key' example, actually I wanted to turn "n" into "j" in normal/movement mode. But keep "n" as "n" in insert mode. (This is because "j" as well as "h,k,l" is part of VIM movement controls which has to be turned into "n,h,e,i" Colemak's equivalent)
Quang
@Quang see the latest addition.
Trey Jackson
@Trey, Awesome! thank you. Works as expected. :) Potentially migrating from vim to Emacs is daunting. I'll be sure to update the basics keybindings of how to get emacs to work with viper+colemak to anyone who's interested. Thanks again Trey.
Quang