413 points · by rawland · 13y ago · 153 comments
I really have my problems, to wrap my head around "hjkl", as there is (imho) no logical mnemonic for the directions. It is sadly just "learn by rote".
" Disable arrow keys
noremap <Up> <nop>
noremap <Down> <nop>
noremap <Left> <nop>
noremap <Right> <nop>
You'll have one or two frustrating days, but after that your muscle memory will take care of remembering "hjkl" for you.I used that arrangement back in the 1980s myself, but when keyboards evolved, so did I. I remapped the movement keys to match the other movement keys (arrowkeys).
If you're going to go to the effort of customizing your vim to force yourself to learn a new keyboard arrangement, customize it so that the movement keys are ijkl instead of hjkl, so that both of your sets of arrowkeys are in the same, natural, modern, inverted-T arrangement. Then you don't have to deactivate those real arrowkeys, because there won't be any temptation to use them with the ijkl keys in the same arrangement and easier to reach.
"Oh, no!" people half my age will shriek. "Then what happens to the 'i' key? This would be impossible." Just use the now-unused key on the left ('h') for your insert-on-left. Reach left to insert on left. There, easy.
Funny how those who insist that YOU should relearn something as fundamental as the entire inverted-T arrowkey structure built into the hardware of every keyboard and used by almost all apps on all platforms including kids' game boxes find relearning a single, arbitrary 'i' key such an insurmountable obstacle to themselves.
But what if you have to use a copy of vim on a machine without your customized .vimrc? Sorry, but that's just an argument against ANY useful customization of vim. It's just not a problem, because the real arrowkeys on the keyboard are in the arrangement you're used to using on the ijkl keys. Just use the real arrowkeys temporarily or copy over your .vimrc. I've done it for years.
But what about other editors that have a vi mode? What about something like zsh with a vi mode? These things can be remapped to match your .vimrc unless they only offer a couple of keys, in which case they can be treated just like all apps with their own couple of local keyboard shortcuts.
Really, if the standard advice is, "You'll have one or two frustrating days, but after that your muscle memory will take care of remembering "hjkl" for you," then you can take your own advice and keep the inverted-T muscle memory you already have for the movement keys and reduce your task to learning a single 'h' key for insertion, and save the next generation from this nonsense.
If a 30-yr user of vi like me isn't stuck with the historical accidents of the past, why should new users have to be?
The reason for doing this is, for me, simply that it is on the home row, and therefore I can reach it quicker. If you like 'ijkl', fine, do that. I feel more comfortably with 'hjkl'.
Or rather, what I am actually using is 'dhtn', being a Dvorak user. And my delete is on 'e'. Because that is how I like it.
Use whatever you like, but in any case switching from one variant to another (for whatever reason) will take a few days of retraining the muscle memory.
more importantly though, is you should almost never use hjkl in the first place. these are the commands you should be using:
b B w W e E ge gE
H M L I A $ ^ 0 %
{ } [[ ]] [] ][
t<char> T<char> f<char> F<char> ; ,
/<chars>
(search counts as a movement command,
d/foo<enter> will delete everything to foo)
probably the commands i use the most are w b and { }I'm going to try your suggestion though, it makes sense.
I'm surprised you didn't mention it.
(nice rant though!)
I've never got into the habit of using anything other than arrow keys even though I've been an occasional vi user for 26 years. Indeed the ancient model of TeleVideo terminal I first learnt Unix on had arrow keys - although not in an inverted-T:
The only time I use an inverted-T is when playing games that use wasd and it really doesn't make sense there, to the extent that when I used to be really into Q3A I started using asdf. (asdf, unlike hjlk, has unfortunately not stayed in my muscle memory.)
The importance of any sort of t-shape is only clear to me if the user cannot type.
I'm on Emacs but... I'm doing exactly like you. Inverted 'T' arrows on 'ijkl' ("jkl" being, for a touch typist, the default position for already three of four fingers of the right hand).
It makes sense: pro-gamers for example (not programmers but 'pro-gamers') do often use 'wasd' or 'esdf' because most are right-handed, so they use the mouse with their right hand and they use an inverted 'T' arrows on their left hand (both 'wasd' and 'esdf' do work... I preferred 'esdf' backed when I used to game but that was a long time ago).
'ijkl' makes no sense besides for historical reasons.
Let's not talk about Emacs (and I love Emacs) 's totally stupid 'pbnf': that has to be one of the dumbest way ever way to move the cursor.
Yet people would rather catch RSI than take the time it takes to configure their Emacs to use 'ijkl' instead of 'pbnf' (Previous / Backward / Next / Forward... Zomg. They really did this).
Emacs has a lot of other stupid problems too: I saw some people were remapping the totally Control+x (which you need all the time) to other things using ctl-x-map. I'll look into that next.
And I agree with you: it doesn't take long to get use to a logical way of moving your cursor.
Oh well. We won't convince anyone but... At least both vim and Emacs (and probably many others) are configurable so at least the ones who put thoughts into that matter are able to modify their environment to use a saner configuration.
I also disabled Home, End, PgUp and PgDown:
noremap <home> <nop>
noremap <end> <nop>
noremap <pageup> <nop>
noremap <pagedown> <nop>I use whatever my hand happens to be closer to. 85% of the time that's the home row, hjkl. But if my hand is closer to the arrow keys I'll use that, and if my hand is on the mouse I'll use that.
" Arrow keys set up for easy buffer switching
nnoremap <left> :bprev<cr>
nnoremap <right> :bnext<cr>
nnoremap <down> :buffer #<cr>
nnoremap <up> :buffers<cr>:buffer<space>But non the less, the logic didn't register with me. (something like clockwise/counter-clockwise, or anything remotely recognizable ;-) )
Remapping the movement keys in Worms Reloaded also helped massively, though did result in me getting completely thrashed for the first twenty or thirty matches I played.
http://jwvideo.free.fr/ImagesMac/AppleII/Apple%20II%20int%C3...
I've always thought that was so much better than the inverted T on PC keyboards, since you can press all the keys without moving your fingers - much faster for games.
Once you have integrated them in your workflow, you'll wonder why you even got into the trouble to force yourself to use hjkl instead of the arrows.
"hjkl", as there is (imho) no logical mnemonic for the directions.
left: "h" is leftmost in the groupright: "l" is rightmost in the group
down: "j" extends down below the baseline
up: "k" extends up to the topline
These four keys are the most basic thing about vim. Yes there doesn't seem to be much to remember them by, but for these at least, there doesn't need to be. Just muscle through it as long as it takes. It won't take long if you're using vim regularly. Soon you won't think about it, you'll just think "up" and you'll be up a line without consciously thinking "... um ... k".
There are ways to get around these four: arrow keys, macros, whatever. Don't. Just learn them.
Bonus, those keys show up in other vim-like command interfaces, including bash and other shell command line shortcuts. And if you use .inputrc, they'll show up in database and language repls and similar environments.
Just learn them.
Display a big arrow, grab an input, make a nice boop noise if it's right and a nasty beep noise (with a graphic flash) if it's wrong. Keep score of how many key presses were right, and average time for each press.
· Control-H is Back Space: it moves the cursor one position left.
· Control-J is Line Feed: it moves the cursor one line down.
The other two seem to be arbitrary on the part of the ADM-3A designers, and having Control-L (Form Feed) perform cursor-right rather than clear-screen seems a bit dubious, but given their constraints and the desire to keep all the motions together, it's hard to argue for any different choices.
Oh, this `j` key has an inset to distinguish it from the rest. Surely this means I need to press this one!
(You can easily figure out the three other keys from there).
H & L are left & right - fairly intuitive, leftmost is left, rightmost is right
J looks kinda like a down arrow
That leaves K, which must be up by process of elimination :)
h: move left ctrl-h (which is backspace in ASCII): move left a space while doing something
j: move down ctrl-j (line feed): move down a space while doing something
Unfortunately, this doesn't extend to k (vertical tab) or l (form feed), but... maybe it's helpful?
If you need to practice, play robots or nethack...
Nowadays I don't even need to think about using any of those keys for moving around. In fact, I use them in pretty much every application that supports them, including Firefox (with pentadactyl) and less.
(I started to write "and my middle finger (on K) is pointing up", but then I realize that an upward-pointing middle finger means something entirely different.. <:)
At least some of you now understand that these tools were designed as you see them today because they were dealing with crippled hardware (from today's vantage point). There was no magical study on keystroke efficiency at the inception. They had lemons and made lemonade.
Now, quit arguing and get back to reading Facebook!
Yup, that's me ducking in the corner.
It's also true that functions can be mapped to arbitrary inputs and systems. But I think there's value in learning HJKL rather than remapping them:
1. They're on the home row, giving a slight speed benefit for these commonly used actions.
2. You get used to the movement keys that will be the default in any copy of Vi/m and quite a few other tools. (HJKL, along with WASD and dedicated arrow keys, is probably the most common mapping of left, right, up, and down to keys on a keyboard.)
Arrgh. This is an example of why programmers are different, not of a bad interface for ordinary people. Thanks for considering me so daft as to think non-programmers people use VIM.
I could agree with you and get the anti-vim guys all worked up. I could even back it up with random links and examples from all over the web.
I could also disagree with you and get pro-vim guys all riled-up. Again, suitable links, stats and a photo of some guy with carpal-tunnel would do the trick.
That's great stuff!
To quote one of the most memorable lines in motion picture lore:
"Interesting game. The only way to win is not to play."
I use vim. And I've used everything else. I don't care. All of it pales in magnitude to the efficiency losses elsewhere in the process of developing a software product.
My guess is that on a daily basis I waste more time going for a cup of coffee, shooting the shit, reading/posting on HN, getting pulled in all manner of directions on the internet than any text editor could save me short of a brain-to-code interface.
And, of course, there's the actual work of figuring out how to code something. I've spent days diagraming state machines with, yes, hold-on, paper and pencil. Once there, an hour or two and the bug-free code is written and working. Yes, even if you use Notepad.
You want to be more efficient? Get really good at going from problem to finished, shippable, documented, flexible, reusable and bug-free code. What you use to enter said code probably does not matter.
I'm going back to polishing my keyboard.
Maybe you guys ought to do the same.
:set incsearch
:set hlsearch
(ObFlameRetardant: I prefer Emacs myself for programming, but vim is a perfectly excellent editor.)(also Enter, ESC, space, delete, backspace, etc etc)
The terminfo entry seems to confirm this (apt-get source ncurses-term && less +/^adm3a ncurses-5.9/misc/terminfo.src):
adm3a|lsi adm3a,
OTbs, am,
cols#80, lines#24,
OTma=^K^P, OTnl=^J, bel=^G, clear=\032$<1/>, cr=^M, cub1=^H,
cud1=^J, cuf1=^L, cup=\E=%p1%{32}%+%c%p2%{32}%+%c,
cuu1=^K, home=^^, ind=^J, kcub1=^H, kcud1=^J, kcuf1=^L,
kcuu1=^K, rs2=^N,
I think the speculations about ^ in regexps coming from the same source are misplaced, because I think the ed editor was already using ^ to mean "beginning of line" before there were any CRT terminals.The ADM-3A had direct cursor addressing, as referenced in the "cup" capability in the above terminfo entry, so the "home" feature was, strictly speaking, redundant. As you can see from the simplicity of the terminfo entry (notably its almost complete lack of escape sequences) logic was aggressively minimized in this termainal. I seem to recall from glancing inside the ADM-3As I bought at auction in my childhood that it was built almost entirely out of discrete 7400-series logic, so every extra control character involved adding several chips.
In light of this, I suspect that the "home" feature may have been retained for backwards compatibility with something else — maybe the ADM-3? But the ADM-3 terminfo entry doesn't mention "home", so I don't know.
More details about the ADM-3A can be found at <http://manx.classiccmp.org/details/11,5618>.
C and Java programmers.
This is not entirely hilarious when a junior sysadmin 'tidies up' the keyboards connected to the main database server (and even further from funny when the slave is currently down for maintenance ...)
http://docs.oracle.com/cd/E19683-01/806-6642/images/BR.unix....
I still had the e1000 (and disk array) which was skip dived until last year but the wife made me get rid of it :( She didn't want that kind of coffee table...
He could have gone for wasd or ijkl. But he had to go with hjkl!
Anyway, the fact that j looks like a down arrow is a very good thing that makes me remember it and allow me to play nethack.
lmgtfy is hateful because it often links to the same search that the asker has previously done, and returns the same not-useful hits. But the answerer doesn't check the returned hits, and just smugly slaps lmgtfy in to "teach" the asker a lesson about searching before asking.
Actually, I stumbled over that question during my quest of unifying my keyboard-layouts (Mac=Work and Linux=Private) via xmodmap.
Unless you're just trying to simulate an Apple keyboard configuration on Linux, that is.
Why do we use X?
Because N years ago, the environment looked like E1, and so X made sense. Then, people got used to X as a convention, and even though our environment changed to E2, we still use X because of network effects.
A great way to improve the world is to understand where X came from, understand how E2 differs from E1, and then invent Y to better fit E2.
The hard part is that Y needs to be significantly better than X so that you can get people to switch given that X has stronger network effects.