11

Is there any way to map the k key to 'down' and the j key to 'up'? This seems much more intuitive to me, since the right arrow will also move the cursor down, if it's at the end of the line.

Why was this mapping decided on? And why does the left / right movement not also take you to the next line like in most other editors?

4
  • 4
  • 1
    Wikipedia suggests the above followed from ^h for backspace and ^j for return, apparently since ancient times.
    – Eroen
    Mar 14, 2012 at 6:17
  • 7
    There are a large number of applications that follow the vi/vim as a standard. You are going to drive yourself nuts.
    – Zoredache
    Mar 14, 2012 at 7:25
  • 2
    Why was this mapping decided on? because the ADM-3A terminal was designed that way. But why such that design? Because once you're in the home row then the index finger will lies on the J key. Since the index finger is the dominant one (just less than the thumb) unless you're a leftie, it's easier and more natural to use that for going down
    – phuclv
    May 10, 2019 at 16:07

3 Answers 3

22

You can do it, but this is a Bad Idea™! This is going to cause you grief down the road.

However, if you are dead set on doing this, put these two lines in ~/.vimrc:

:nnoremap j k
:nnoremap k j

As for left/right moving wrapping on lines:

:set whichwrap+=h,l

See :help 'whichwrap' (with the single-quotes), and note that the help says this is not recommended.

6
  • 2
    Thanks for the info -- super helpful. But is it only a bad idea because I'll get confused on other systems? I assume that these were put in that order for some ergonomic reason or something. Any idea what it is? (Or is it just history, as comments above suggest?) Thanks! Mar 14, 2012 at 17:31
  • 8
    The confusion is basically what is at issue, but don't discount it; this will be more of an issue for you than you realize after you have gotten used to your nonstandard movement keys. There are other problems you may run into with Vim itself, possibly with plugins, for example..
    – Heptite
    Mar 14, 2012 at 19:54
  • 2
    Things have really come a long way since 2012! Now that I'm used to the j and k keymap, I can't live without it. I 100% agree with this answer -- BAD IDEA. Oct 21, 2016 at 13:04
  • 2
    @SauceMcBoss Can you elaborate? Exactly WHY do you think it was a bad idea? (I'm just curious because I'm considering remapping) May 22, 2020 at 23:52
  • What difference :nnoremap with nnoremap (without colon) ? Sep 16, 2021 at 20:24
6

Bill Joy wrote Vi on the ADM-3A keyboard, seen below:

ADM-3A

It didn't have its own dedicated arrow keys, but had arrows associated with the letters as seen on the keyboard. It's a Unix thing, too, or was.

5
  • 3
    Hi. May I know how does this.. answers the question? (sounds like a comment to me.. (if it is.. move the post as a "comment" instead)
    – p._phidot_
    May 10, 2019 at 0:14
  • 2
    Part of the question asks “Why was this mapping decided on?”  This post shows that the developer of vi was intimately familiar with a keyboard where the “J” key was the down key and the “K” key was the up key, so it offers an answer to that part of the question. May 10, 2019 at 1:06
  • this was actually mentioned in the first comment on the question 7 years ago
    – phuclv
    May 10, 2019 at 16:09
  • Is this related to being a left-hand or a right-hand person ? Was the person who invented this keyboard a left-hand guy ? Is it more logical for a left-hand person to go down with j ? The same happen with Firefox, you move up in the tab by pressing CTRL+PAGEDOWN. Very counter intuitive for me. And it seems to concern a majority of peoples and as the majority is right-handed, I'm thinking that it could be related.
    – nikau6
    Mar 29 at 0:45
  • The same happen to with the Gnome to move from one desktop to the other. If it's not a right-hand, left-hand, thing, is this just a habit some peoples took by using Vim and now they're spraying this habit all over the place in many software.
    – nikau6
    Mar 29 at 0:54
2

Adding these here to fix a missing detail in the original answer. The window navigation is broken if you only remap k j.

The complete remap is:

noremap k j|noremap <C-w>k <C-w>j|noremap <C-w><C-k> <C-w>j
noremap j k|noremap <C-w>j <C-w>k|noremap <C-w><C-j> <C-w>k

Regarding plugin compatibility... I've been using this for months with many plugins in my setup. If you happen to find any plugin that has a conflict, just fix the plugin key-maps, but after installing around 20 different plugins, none has given me any issues with this configuration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .