Hacker News new | past | comments | ask | show | jobs | submit login

Arrow keys work fine in VIM, whether you're in insert mode or not. The argument for not using them is that it's less productive to use them than HJKL, because you need to move your hand back and forth between the home row and the arrow keys.

I never broke the habit myself, and I suspect the benefit is a lot smaller on a laptop keyboard versus an AT keyboard.




I highly recommend getting used to it. Being able to keep your hands on the home row, even on a laptop, is a huge boon; I can't really claim it's a productivity increase (I have no idea if it is), but it just feels so much better and more fun to type that way.

Actually, the same is true of most vim stuff: does being able to delete text 2 seconds quicker really make you more productive? Beats me. But after you get used to being able to tell the computer what you want to happen and have it happen (e.g., delete everything inside these parentheses), using the old method of moving around the cursor just feels bad.


I've never understood this. I have to take my (other) hand off to hit esc and get out of insert mode anyway. Additionally the fact that vim (as opposed to vi) gets rid of the diagonal movements negates a lot of the benefit for me. I also switch into "nethack" mode when I try to use hjkl and that's never good for productivity.


It's a shame that all tutorials apparently tells you to use ESC to get out of insert mode. The real way to do it is Ctrl-c, which keeps you on the home row. It works even better if you map Caps Lock to Ctrl.


You can also use Ctrl-[ to go to normal mode.

Ctrl-O takes you to normal mode for a single command and then automatically goes back to insert mode.

Frankly, I find it easier to map Caps to Escape. Only problem is when you use other people's systems and you keep hitting caps lock when you mean to hit escape (Even if you're not in Vim)


The trick with mapping Caps Lock to Ctrl is that you can use it for all your regular Ctrl-shortcuts. At least on MacBooks the regular Ctrl is placed totally impossible.

But yeah, I /can't/ use others computers without getting utterly frustrated because of that. :)


There are two tricks to fix the escape problem.

First, you can use ctrl+[ to get out of insert, which means moving your hands less.

Even better (but requires customization), you can remap "jk" to get out of insert mode. Since "jk" is a combination that never comes up in actual writing, it works great. And it means you don't have to move your hands at all from home row.


To help the parent and or vim newbies avoid a google, and to show why this "customization" isn't scary or hard, all you need to do:

    :imap jk <Esc>
(Literally type the angle brackets.) And if you want this as a standard default, make a .vimrc file in your home folder and stick the above without the colon in there.


I love you both.


In English, maybe. In Danish there are plenty of jk's in actual writing. Ctrl+[ is terribly inaccessible on a bunch of international keyboards. Ctrl-C is the good one, really.


The point is to map some easily-typed, but rarely-used, key combination as your escape key. I use jj. On the rare occasions I have to actually type jj, I just wait about a half second after typing the first j, and then the second j is received as a separate keystroke, and not interpreted as the second part of a mapping.

And the only times I remember having to actually type jj are when I'm having the Vim keymapping conversation with somebody who asks "So how do you type 'jj'?


Clearly the right way is 2ij^[

:)

(EDIT: uhh, the :) is a smiley, not part of the command)


If you have a proper keyboard with a wrist rest, you only have to extend your fingers to press esc (not actually lift your hand, or move your whole hand which requires moving your whole under arm, if you're typing on a keyboard without wrist rest and where you have your hands hover over the keyboard. Ctrl-c requires you to twist your wrist in an awkward angle, several times a minute. If you keyboard really puts the esc key far away from the home row, you can remap caps lock to esc.

All of this assume that you type 10-finger blind, but I guess if you can't even do that you have other priorities than learning vim.


Taking your hands off of home row to get out of insert is also easily soluble -- you can map literally any key combo to esc. I use command-i (on a Mac), which is effortless to type and feels nicely symmetric to using i for insert.


The far better argument for not using arrows while in insert mode is that it hinders the learning of the difference between insert and normal mode. Once you get used to there being a strong difference between the two, you end up using the more useful motion commands such as f/t or ) or #/*. these motions usually get me to where I want to go faster than hjkl would, not to mention the benefits of being able to compose advanced motions and commands.

When I help people learn vim, one of the first things I do is disable the arrow buttons in insert mode. I tell them that they should avoid using them even in normal mode. I feel that this crutch ends up hurting you in the end. On the other hand, writing text in non-vim contexts is maddening with all it's arrow-arrow-arrow-backspace-backspace-backspace pain. I don't see how 99% of people can stand to do it this way :)


Here is another good read on vi/vim.

http://www.viemu.com/a-why-vi-vim.html

See "misconception #4" for this particular point.


This is by far the best vi/vim introduction I've ever read. Not because it makes you instantly proficient with the editor -- there are other tutorials for that -- but because it does an excellent job explaining how to use it properly.

In Vim, especially the GUI version, it's perfectly possible to just press 'i' and then putter around in your text file, moving around with cursor keys and Home/End and such, deleting, typing, and only occasionally dropping back into "command mode" (as it is often called) to delete a line, or search for something, or save the document (assuming the GUI version doesn't have key bindings set up for this already). I used Vim like this for over a decade, never really understanding the point.

As the article points out, this is completely wrong. You stay in command mode (called "normal mode" here, which gives it a different feel immediately -- it's the mode you normally should be in), and switch to insert mode only to type short bursts of text. Everything else is done in command mode.

While this seems weird at first, once you start getting the hang of it, it starts paying off big time. There are a zillion commands that do something and then enter insert mode. I used to think they were completely redundant; there's already 'i' and 'a' to do that, why have more? Because, obviously, when you spend most of your time in "normal mode", this allows you to execute a command and immediately start typing text. E.g. to insert a new line below the current one, you press 'o', and Vim inserts the line, indents it properly (if you have autoindent set), and is ready for typing.

While this is hardly heavy wizardry, once you know a couple dozen of these commands, editing becomes a very different experience. You just move through the text differently.

Anyway, the article explains this, and a lot more, much better than I can do it here. :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: