2

I admit that I'm not an expert vim user so forgive me not providing previous attempts!

I wish to overwrite/remap the basic vi/vim (and gvim) "cursor keys" hjkl to the ordinary "gamer layout" wasd (w-up, a-left, s-down, d-right). Moreover: I know that "w", "a", "s" and "d" are important keys in vim so I came up with the idea to remap hjkl to ALT + wasd.

Have to configure .vimrc? Or is there some plugin? Can you help me?

Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
Tom Solid
  • 2,226
  • 1
  • 13
  • 32
  • 1
    I don't have enough reputation to change your [identical question](http://unix.stackexchange.com/questions/293753/vim-set-cursor-keys-hjkl-to-wasd) at the Unix Site but I assume you meant ALT. – Lieven Keersmaekers Jul 04 '16 at 11:23
  • @LievenKeersmaekers: thanks, yes I meant ALT. Edited at Unix Site. – Tom Solid Jul 04 '16 at 11:34
  • What do you see when you open a terminal, run the 'cat' command, and enter the following keypresses in sequence: `Alt-w`, `Alt-a`, `Alt-s`, and `Alt-d`? – zarak Jul 04 '16 at 12:01
  • @zarak: `^[w` `^[a` `^[s` and `^[d` – Tom Solid Jul 04 '16 at 12:05

3 Answers3

4

Map your Alt + aswd to hjkl; in your .vimrc

noremap <A-a> h
noremap <A-s> j
noremap <A-w> k
noremap <A-d> l
dNitro
  • 5,145
  • 2
  • 20
  • 45
  • Would this work with the Alt key? I think it suffers from the problem described [here](http://stackoverflow.com/questions/5379837/is-it-possible-to-mapping-alt-hjkl-in-insert-mode). – zarak Jul 04 '16 at 11:43
  • 2
    @zarak, Tanx, Maybe BUT That's a separate issue. Its totally terminal based! @Tom Solid, you should examine what escaped sequence is being sent to vim when you for example pressing `ALT + a`, use the refrences that zarak is introduced. – dNitro Jul 04 '16 at 12:14
2

According to zarak's and dNitro's solutions, in my case adding

noremap <Esc>a h
noremap <Esc>s j
noremap <Esc>w k
noremap <Esc>d l

to .vimrc solved the problem.


Because in my case

cat
ALT-w
ALT-a
ALT-s
ATL-d

resulted ^]w ^]a ^]s and ^]d.

Thanks a lot!

Community
  • 1
  • 1
Tom Solid
  • 2,226
  • 1
  • 13
  • 32
1

I think adding this to your .vimrc should do the trick.

noremap ^[a h
noremap ^[s j
noremap ^[w k
noremap ^[d l
zarak
  • 2,933
  • 3
  • 23
  • 29
  • Ah I misunderstood your question. dNitro's solution should work then, if you type in the characters your terminal generates. – zarak Jul 04 '16 at 12:09