
Vim users: stop using hjkl - nelstrom
http://vimcasts.org/blog/2013/02/habit-breaking-habit-making/
======
roel_v
Linkbait title alert. Please, please stop this crap. Article really says: n00b
vim users, consider disabling hjkl while learning other movement commands.

What vim user does all their movement with hjkl only anyway? If you're going
to deliberately cripple your editing habits like that, or if you're not even
bother to learn other movement command at the same time as getting used to
hjkl, you might as well stick to notepad.exe.

~~~
kingmanaz
>What vim user does all their movement with hjkl only anyway?

Having used vim for nearly two decades now, my primary movement routine seems
to be start with "/" and "?". In other words, jump to the approximate location
using a word search and "W" or "w" as needed to the specific word, then use
the hjkl or other commands to further refine the cursor's location.

~~~
lutusp
> Having used vim for nearly two decades now, my primary movement routine
> seems to be start with "/" and "?". In other words, jump to the approximate
> location using a word search and "W" or "w" as needed to the specific word,
> then use the hjkl or other commands to further refine the cursor's location.

Young programmers should be made aware that there are now programming editors
that do away with the need to think of a way to trick the program into moving
the cursor where you want it to go. Modern editors respond to direct, concise
keyboard entries to move the editing cursor to the desired destination. Like
pressing the arrow keys. Or pointing at the destination with a mouse and
clicking -- things like that.

Even ubiquitous command-line editors like Pico are easier to use than vi/vim.
The reason is that Pico doesn't have vim's history to contend with, and its
consequent rearward compatibility issues.

~~~
roel_v
Not sure if just trolling, but if not it seems you're not very experienced yet
in the use of the tools of the trade of the professional programmer. The point
of using the vi interface is nowadays (and yes I know about the original
reasons of the modal workings of vi...) that moving your fingers off the home
row takes too much effort, let alone having to move your hand to the mouse.
It's easier to drive an automatic, why do professional drivers switch gears
manually? Because learning the more advanced interface gives them more control
over the way the machine behaves, and in their use case, the investment in
learning it pays off handsomely in the added power later. Should regular users
bother to lean vi? No. Programmers? Yes.

~~~
lutusp
> Not sure if just trolling, but if not it seems _you're not very experienced
> yet_ in the use of the tools of the trade of the professional programmer.
> [emphasis added]

Guess again -- I wrote Apple Writer in the late 1970s
(<http://en.wikipedia.org/wiki/Apple_Writer>). One of my goals was to
eliminate the modes that plagued contemporary editors and attract people
interested in ease of use and efficiency. Apple Writer became a best-seller
because (among other things) its competition, most derived from vi, required
users to switch modes.

And I can't believe I'm having this conversation over 30 years later, still
trying to get people to choose more efficient tools.

> ... you're not very experienced yet ...

It's likely that I was programming -- and publishing my programs -- before you
were born:

<http://arachnoid.com/programmable_calculators>

~~~
tikhonj
There's a difference between "more efficient" and "easier to learn". You're
advocating the latter. This is not a good thing.

For example, moving around by using the search feature (at least a well-
designed incremental search like Vim or Emacs) _is_ more efficient for longer
distance moves (e.g. more than a couple of lines)--it's faster and, more
importantly, takes less thought and context switching.

When you have to move to a distinct part of your text file, chances are you
know what the content there is. With a command like /, you directly turn that
knowledge into efficient movement. With the arrow keys, you have to leave the
home row and do a bunch of movements to get where you're going. You have to
figure out how to turn the word you want to go to into a bunch of arrow
actions. It's even more difficult of your target is off-screen.

Ultimately, a rich set of movement commands you can access without moving your
hand is going to be more efficient than using the standard arrow keys. This is
particularly true for somewhat semantic commands like moving by block or
expression or moving to a word (the command in question here).

Ideally, you want to move around faster with less context switching. Keyboard-
oriented editors like Vim and Emacs are much better at this than any other
editor I've seen, as long as you learned how to use them properly. This really
makes the learning curve more than with it.

~~~
lutusp
> There's a difference between "more efficient" and "easier to learn". You're
> advocating the latter. This is not a good thing.

You've posed a false dichotomy. Modern editors are both more efficient and
easier to learn.

> Ideally, you want to move around faster with less context switching.
> Keyboard-oriented editors like Vim and Emacs are much better at this than
> any other editor I've seen, as long as you learned how to use them properly.

Pico is a keyboard-only editor, and it's easier to navigate, and to use in
general. So is every other editor that exists, written after about 1980. None
of them require the user to switch modes, an idea that died with vi -- I mean,
if only vi had died.

As soon as keyboards included arrow keys, the handwriting was on the wall.

~~~
nsmartt
How is a mouse more efficient than an ability to move to a phrase with a bit
of typing, skip words ahead with a single letter instead of ctrl + shift, move
to a new line and a specific place on that line with a couple of button
presses, etc?

~~~
lutusp
> How is a mouse more efficient than an ability to move to a phrase with a bit
> of typing, skip words ahead with a single letter instead of ctrl + shift,
> move to a new line and a specific place on that line with a couple of button
> presses, etc?

I can't improve on your explanation as the answer to your own question.
Obviously using a mouse to cut/copy and paste, within the same document or
between independent documents, is more efficient than what you just described.

~~~
nsmartt
Moving my hand over to the mouse, moving the mouse cursor to wherever I need,
selecting that text and dragging while my editor slowly scrolls with my cursor
when I could use a few key sequences with no context switch is the opposite of
efficient.

edit: wording

~~~
lutusp
Pro tip: don't downvote a correspondent from whom you also expect a reply.

~~~
nsmartt
If you check my profile, you'll see that I have less than 500 karma and
therefore could not have downvoted you.

edit: wording/lower verbosity

edit: typo

~~~
snogglethorpe
Also HN doesn't allow downvoting of direct replies...

------
lutusp
> Moving your Vim cursor around using the arrow keys is a bad habit ...

Yes, as is having a keyboard with more than 64 keys, a pointing device,
software that allows character insertion, deletion and cursor motion all
without changing modes, or any computer designed after 1980. We must all fight
against this rising tide of convenience and efficiency by insisting that
everyone use vim and its descendants.

~~~
JulianWasTaken
This comment is ridiculous.

Being "anti-vim" is perfectly alright with me. I use vim because it's the
fastest thing I've ever used by a very wide margin. I also respect others who
find it too hard to learn or find they're more productive elsewhere.

But a comment that essentially boils down to "vim is archaic" in a _post about
vim usage habits_ is totally ridiculous, so in the nicest way possible, get
lost.

~~~
lutusp
> But a comment that essentially boils down to "vim is archaic" in a post
> about vim usage habits is totally ridiculous ...

And entirely topical. Young programmers who read such posts may not realize
how many more efficient options are now available. Speaking about vim as
though it's an obvious choice in 2013 would be like insisting that everyone
code in Fortran in 2013.

~~~
sofal
You're commenting on a vim post in order to help lost young programmers
understand that there are other options besides vim?

 _Speaking about vim as though it's an obvious choice in 2013 would be like
insisting that everyone code in Fortran in 2013._

Oh, now talking about how to use vim effectively is like _insisting_ that
everyone uses an archaic programming language? I suppose if we were to have a
post here talking about how to use the command line effectively, you'd feel
obliged to educate young programmers that we've moved on from the 1970s.

~~~
lutusp
> You're commenting on a vim post in order to help lost young programmers
> understand that there are other options besides vim?

Yes, and what better place?

> Oh, now talking about how to use vim effectively is like insisting that
> everyone uses an archaic programming language?

Based on the number of objections to a discussion of vim's alternatives, yes
-- that's a legitimate comparison.

> I suppose if we were to have a post here talking about how to use the
> command line effectively, you'd feel obliged to educate young programmers
> that we've moved on from the 1970s.

Only in the midst of an amazing discussion that included various "cheat-sheet"
strategies to get around the behaviors of an editor that demands cheating to
be productive. Given that context, saying that newer editors don't require you
to cheat seems entirely topical.

------
jlongster
It's amazing how fast you can retrain muscle memory by disabling certain keys.
It's frustrating for about half a day, then kind of annoying for a day or two,
and then you've completely retrained yourself. In just a day or so!

However, I like to fiddle with the cursor while I'm thinking. Might be just
me. I don't like feeling like I'm completely constrained. It's nice to
casually move around when I'm pondering something deeply.

When I'm seriously coding though, I almost exclusively use move
forward/backword by word or expression, and then use ace-jump to arbitrarily
jump to specific points (<http://www.emacsrocks.com/e10.html>). I use Emacs of
course.

~~~
bdc
> I like to fiddle with the cursor while I'm thinking.

That's a good point - I do that too. Also, if I've switched my attention
somewhere else, then back to vim, I find myself doing "hlhlhl" to get my
attention back to the cursor immediately.

------
gingerlime
I was hoping someone would trash the idea of hjkl, which I personally don't
like. So first I was disappointed to read yet again about _not_ using the
arrows.

Then when I read the rest of the post, it definitely makes sense. I do use w,
b quite frequently, and I don't use f, but I've found the vim-seek[1] plugin
recently, and it seems to make more sense to use. It matches two rather than
one character, which makes it much more precise.

I think the bottom line is to move around to the _right place_ and that going
one character at a time is less efficient. Not so much whether this movement
is via hjkl or the arrow keys.

[1]<https://github.com/goldfeld/vim-seek>

~~~
goldfeld
I'm now considering extending the seek idea to moving to close-by lines,
through mappings that would work like EasyMotion's w, b, e and ge but
excluding the current line and working on lines above (b and ge) and below (w
and e), by typing the two characters that respectively end and begin the
target word.

~~~
gingerlime
sounds cool. One thing I couldn't work out with the plugin, was how to skip to
the next match. It's rare that two letters match, but some letter combinations
are still relatively frequent, things like `if` or `th` ... but perhaps it's
just a RTFM issue and I haven't used it extensively yet...

~~~
goldfeld
Yes that's on the pipeline, doesn't work yet. I agree it would come in really
handy on the few occasions we seek for a more common letter combination.

------
hartator
What I like about VIM people is they explain you that mouse is evil, arrow
keys are evil and now the basic hjkl (btw corrected into hell in iPhone
keyboard) are evil too.

I have even see a guy at a ruby conf who were using only keystrokes to browse
the web. I wonder how it deal with flash animation. Anyway so now, he can
replace his trackpad with a swimming pool for worms of smugueness. That's
pretty cool.

~~~
icebraining
We don't deal with flash. We curse the foolish website developer and route its
domain to /dev/null. Using VIM.

~~~
hartator
Anyway, why use the web when you can use directly sockets? Faster, more secure
and grep-compliant.

------
robomartin
Oh please, not vim again. Now you are not even supposed to use the already
ridiculous hjkl mappings. It's really amazing to me to see this sub-culture
attach itself to an editor that was designed as it is BECAUSE THE AUTHORS DID
NOT HAVE KEYBOARDS WITH MORE KEYS ON THEM!

"hjkl is faster than reaching for the cursor keys". Holy frigging crap!
Really? You are so good as a developer that MILLISECONDS make a difference? It
does not take you hours to come up with algorithms or program structures to
solve problems. And, when you do, you write code at blinding speeds (using
vim) with NO BUGS, therefore MILLISECONDS matter because you are not one of
those programmers who will need to spend HOURS hunting down and fixing bugs.
Oh, yes, and 100% of your time is spent coding. You don't lookup documentation
and you don't do any file management at all. You are a damn coding machine who
can actually measure productivity by the millisecond and who must absolutely
use the shittiest possible UI in the context of modern hardware to shave
milliseconds from your every keystroke. You never reach for your iPod to look
for music or read through HN, Facebook or even your email throughout the day
because that wastes minutes. You never take a break, shoot the shit or
theorize and ponder with your coworkers because you measure your life by the
MILLISECONDS of flight time difference between the hjkl keys and the up, down,
left, right keys 12cm away.

Right. The reality is that this is just a "I belong to the club" delusion that
has nothing whatsoever to do with being a good programmer, writing good,
clean, usable, extensible, reusable, fast, efficient and bug-free code. It has
nothing whatsoever to do with delivering a product anyone wants and doing that
on time and on budget. It has nothing whatsoever to do with being an
entrepreneur, building a company, paying the bills and delivering value to
users and investors alike.

It has everything to do with being a complete child and refusing to understand
that there are places where you could optimize your time and energy that
represent, without exaggeration, PRODUCTIVITY GAINS IN THE ORDER OF MILLIONS
TO BILLIONS OF TIMES GREATER than the time required to reach for arrow keys
or, Darwin forgive, the MOUSE (yes, he used that word) a few hundred times per
day.

Grow up!

~~~
goldfeld
A lot of people who don't understand what vim is before criticizing it seem to
miss the point that vim doesn't make you faster at writing code. Insert mode
is a dumb text entry mode like any other, and Visual Studio and Textmate in
fact have out of the box more tools for snippets and auto-completion than most
vim users care to even supplement with plugins. Because the power is in
editing text, not writing it. And oh, how convenient, programmers spend like
10% or less time writing and a whole lot more reviewing (moving around) and
editing code.

~~~
robomartin
I'll tell you when and why I use vim and how I can justify its useage: Linux
servers. I use vim on my servers to edit everything. Why? Because I know it's
there and I don't have to install anything. And, even though I think it's a
horrible UI that could only be justified in an era with keyboards that barely
had characters and numbers, I use it.

A religious attachment to vim? No friggin way. No editor has ever caused one
of my projects to come in late (or early). The factors that affect real
projects are so far removed from the software one uses to edit code that it is
incredible some people evangelize something like vim to such an extent.

The other really funny thing is to see articles and blog posts describing how
to add trees, tabs and all manner of other things to vim and how this makes it
even cooler. Really funny.

~~~
avenger123
I agree with the usefulness of Vim on Linux servers. I would say that everyone
is different in how they approach their work and in the case of software
development, the tools they use.

I wouldn't consider it funny that someone would want to optimize a very
important tool to make it more functional. The tools we use for software
development are both a curse and a blessing. A curse that there is no ONE TRUE
WAY of doing something and a blessing that we can build and mold the tools to
accomplish what we need.

I am not religious about Vim or any other text editor but I can definitely
appreciate others wanting to optimize their usage.

Personally, I find that once you have setup Vim the way you want, its pretty
much on autopilot. I would say that if someone is a natural tinker, Vim is the
best black hole one can get into as there can be no end to the tinkering.

~~~
robomartin
Yours is an absolutely reasonable non-fanatical position on this topic. No
issues whatsoever.

My blood pressure goes up when people start to get religious about this stuff.
Some go as far as proposing that one can only be a professional programmer if
one uses vim, which is utter nonsense.

~~~
goldfeld
Well you've come off as quite the extremist shouting to the rooftops that
people shouldn't try to be super efficient with vim. People who might not go
out on a limb to say everyone should do it too. As for your comment on tabs
and trees, sorry, those are heretics. True vim followers use buffers only.

~~~
robomartin
> Well you've come off as quite the extremist shouting to the rooftops that
> people shouldn't try to be super efficient with vim.

That's the point. vim does not make you super-efficient at anything other than
being a data entry clerk. That's not where significant value is developed in a
technology business.

> True vim followers use buffers only.

Don't forget a Lear Siegler ADM3A terminal over a 300 BAUD modem leased line
to the mainframe. Oh, wait, that's the way it was when vi was written.

:-)

I love this quote from Bill Joy: "I think if I were going to go back—I
wouldn't go back, but start over again."

<http://web.cecs.pdx.edu/~kirkenda/joy84.html>

------
mieubrisse
Most of the comments in this thread can be summed up with: 1\. "Vim sucks/is
better than _____ because...." 2\. "Finally, somebody's preaching the truth!
Who even uses the HJKL keys? Not me..." 3\. "I think I will/won't consider
adding 'w', 'b', 'f', etc. to my Vim inventory because..."

1\. This is not a productive comment, and this thread isn't here for you to
start an argument on something rooted in personal taste. Your're entitled to
your view, but this post was written as a suggestion for Vim users, for Vim
users. Please, refrain from posting if that's all you have to say.

2\. That's great that you've found more efficient ways to navigate, but did
you read the article? Though it's impossible to tell from the extremely-
misleading post title, the article isn't polemicizing - it's trying to suggest
tools that a user might not already know/be familiar with.

3\. These comments are the only ones discussing the actual article text, and
are the minority. Let's discuss the merits of what the post was actually
talking about, as the comments are meant to do!

------
goldfeld
I have in my vimrc something I'm calling restrain.vim. In effect it allows me
to rebind a double press such as jj, kk, hh and ll to do something else. That
means I can only press any of these keys once, if I press a second time it
does a different thing (I'm using j and k for jumping to the next line number
ending in 0, or ending with a digit if I supply a count, so it's kinda like
relative line movement with absolute line numbering).

So when I press j once it moves down one line, and if I press any other
command it's reset so I can press j once again next time (so it allows going
down a line and pressing . repeatedly). But from the second consecutive press
each single j press will be doing another thing. This is helping me a lot with
retraining to using other methods to get around instead of spamming j. Wait,
that's a good wordplay, restraining, retraining. Hmm..

------
fnordfnordfnord
Hard mode, that's great. Does vim have a help-a-fellow-learn-vim mode? Instead
of it's normal Mostly-fail-to-give-you-any-visual-feedback-and-just-treat-you-
with-smug-indifference-while-you-try-various-keys mode?

~~~
freehunter
There is a vim tutorial baked in that will walk you through some things.

~~~
fnordfnordfnord
It isn't the first thing one sees upon starting vim for the first time, nor is
it obvious in any other way.

~~~
freehunter
I could swear if you just ran the command "vi" rather than opening a file with
vim it would load to a screen that shows you how to run the tutorial. I can't
confirm that since I'm on a Windows machine at work right now, so I won't
argue it. It does exist, but I'll acknowledge that it's not advertised
heavily.

~~~
fnordfnordfnord
I just freshly installed vi and tried that. Here's what I was greeted with.
<http://pastebin.com/HxvNP6Tr> I've seen the tutorial that you're probably
talking about a few years ago when I got curious about vi. It didn't really do
it for me at the time.

I'm prepared to believe that people willing to tolerate its ideosyncracies can
be very productive in vi or vim. I've seen it first-hand. It also appears to
be well suited to potentially reducing rsi-type problems. But it is not
intuitive to learn nor is it the least bit friendly. That's a shame too
because there is no good reason why it couldn't be so.

------
falcolas
No advice on moving from line to line? Word and character movements are great
(and well worth learning), but how do you suggest moving to _just the next
line_ without spamming `w`?

~~~
wallish
For moving directly vertical:

:nnoremap k gk

:nnoremap j gj

These move up/down one character, even if it is the same line wrapped over.
Really beneficial for things like LaTeX editing.

~~~
imissmyjuno
I was going to say. Disabling hjkl makes moving between word wrapped lines
impossible

------
bilalq
This is excellent advice. I've met so many people who thought HJKL was the
only way to move around in Vim. Moving around with other keys really boosts
your productivity.

------
jodrellblank
If I can see where I want the cursor to be, why can't I put the cursor there
... by looking at it and pressing a 'jump to' modifier, or by touching it, or
whatever.

Even as a Vim fan, this isn't better than mousing, this is similarly annoying
to proxy movement through other things.

------
dmbaggett
I don't even use vi(m) anymore, but hjkl are so burned into my brain that one
of the first things I had to do to <http://inky.com> was make hjkl work to
move around in the message list.

------
pmelendez
I see too many love-hate comments in here, I realize now that people can be
really fanatical about their preferences for editors.

For what is worth, I use vim and visual studio in daily basis, and love both.
I love vim experience over a console and the fact that I can code in a remote
machine without any perceptive latency.

I love visual studio goodies (mostly intellisense) and being a keyword guy I
just learnt VS shortcuts.

So, Is there something wrong with me? for me those are just tools not
religions.

Edit/PS: I know am comparing an IDE and a editor, but in this case I think the
analogy is valid

------
xutopia
I hate hjkl for the simple reason that I learned to type with my index fingers
on F and J keys. I use search a heck of a lot more but I guess I should add w,
b and e to my repertoire.

~~~
calebegg
I also learned to type with my index fingers on F and J (I think it's quite
standard, given the typing classes I took and the little nibs on my keyboard),
and I've always been fine with HJKL. What's the problem you have with it,
exactly? It sounds like you're saying you'd prefer jkl;, but I don't think
that would be better; moving to the left seems perhaps least common to me.

~~~
xutopia
I guess I find myself hitting the wrong keys each time and I'm quite happy
with ; being used for something else.

------
hadem
Some may be interested in the EasyMotion plugin.

Using <leader><leader>f <char> will display all available options to jump to.
This way you don't have to continue to use f<char> over and over if there are
many of the same character in the line you are on. It is also a great way to
jump to a very specific spot in your code.

Note, it also has other motions besides just f. Here is the link:

<https://github.com/Lokaltog/vim-easymotion>

------
s00pcan
I use control keys for a lot of my movement. <c-f>/<c-b>, <c-u>/<c-d>,
<c-e>/<c-y>, <c-n>/<c-p> (remap your ctrlp plugin to leader p. This is vim.)
And yeah, I have caps lock remapped to control. Setting virtualedit=all will
also force you to think in terms of text objects by allowing the cursor to
move everywhere. No longer can you simply press j/k and have it go to the end
of the next shorter line.

------
chatmasta
I've never felt too pressed to learn vim, but I now realize how nice it is to
be able to open the same exact editor with the same exact shortcuts on any
linux machine in the world. I have 20+ servers I need to SSH into on a weekly
basis, and I would much rather benefit from the convenience of using vim on
every one of them than some hacky SFTP solution with Sublime on my machine.

------
manaskarekar
One of the best (collection of) cheatsheets:
[http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial...](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)

The pdf version can be found here:
<http://www.glump.net/howto/vim_graphical_cheat_sheet>

~~~
TwistedWeasel
I never found the keymap cheat sheets useful. It tells me what happens if I
press a certain key, but what I need is the reverse. Tell we what key to press
if I want X to happen.

When using a cheat sheet like that I waste a lot of time scouring the image
looking for text relating to the type of operation I want. I'd rather have a
list of options grouped by operation type.

~~~
pbarnett
I have a deck of flashcards in Anki to help learn vim bindings in a way
similar to what you're looking for.

The flashcards are designed so the front is a description of some operation
(ex. "motion cursor to end of the line" or "backward find word under cursor")
and the back is the key combo to make that operation happen.

It works really well for me and I've noticed a huge improvement to my
productivity in vim. If you're interested:
<https://github.com/MrPants888/vim_flashcards>

------
aswerty
He gives examples of how to do away with h and k except for one off errors
which is how I work but he doesn't really show a smart way of going up or down
2 or 3 lines without using j and k. I vertically move by using MHL and jk, is
there a smarter way than that?

------
blinry
Another inefficient command that I use way too much is "x".

Using those keys once or twice is, of course, perfectly fine. One could set up
some mechanism that limits the number of repetitions in a row.

------
dseigle
To prevent overusing hjkl a plugin that throttled how many times you could hit
the keys in a row would be ideal. That way they would still work for one off
errors.

------
_nato_
the F,f,t,T commands really changed my life.

However, after using vim for a long time, I still use the arrows! Not all the
time, but a lot. I find that my fingers are always darting around on the
margins using $ an ^ and ~ and ... my argument is what's wrong with traveling
a little to get to those equally distant arrow keys? I don't really consider
the hjkl to be my home position for my hands much. Thumb on space bar is home,
if I had to define it.

------
shmerl
I'm using arrow keys in vim for navigation. Never used hjkl or anything else
for that purpose. I also usually put 'set nocompatible' in .vimrc.

------
snambi
I use hjkl everyday. Its pretty handy. The arrow keys are too far away from
the maon keys. Thats why hjkl is very useful

~~~
pmelendez
I have tried to make that switch several times but still I found more
comfortable the arrow keys (especially because up key is in fact above the
rest)

If I have to pay that fraction of time for the convenient arrangement of keys.
I will pay it happily.

------
kiwim
You chose an awful title, nelstrom.

------
redblacktree
Typing is not the bottleneck.

~~~
saidajigumi
No, it isn't, and that's the major underlying theme of Drew's writings on vim.
This article is no exception. By learning to use the power of the tool, you
work fluidly with the structure of the text, not just the characters/lines.
That is, your expertise of the tool is shaped to match the mental patterns
around the code you work with.

------
agscala
This is okay advice, except that hjkl are actually useful occasionally.
Disabling them will only hurt yourself.

~~~
elbear
The article says that. The title of this posting is a bit sensationalist,
although it's used as a subtitle in the article itself.

