12 ms·
Vim users: stop using hjkl
- hartator 14y agoWhat 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 14y agoWe don't deal with flash. We curse the foolish website developer and route its domain to /dev/null. Using VIM.
- hartator 14y agoAnyway, why use the web when you can use directly sockets? Faster, more secure and grep-compliant.
- kingmanaz 14y ago>I have even see a guy at a ruby conf who were using only keystrokes to browse the web. Try pentadactyl for a couple days. Once you get used to it you will not want to go back to being a mouse-pointer sharpshooter.
- lutusp 14y ago> 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 14y agoThis 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 14y ago> 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.
- mdpye 14y agoPerhaps you'd care to share some of them and their advantages with the younger and older coders who've never come across them? Otherwise - in a slightly less nice way than last time - get lost.
- lutusp 14y ago> Otherwise - in a slightly less nice way than last time - get lost. If that's your argument in favor of vi/vim, then other vi/vim users may ask you not to be on their side.
- kiwim 14y agoOooh. I'd love to hear those many more efficient options!
- lutusp 14y ago> I'd love to hear those many more efficient options! This may come as a surprise, but modern programming editors don't require the operator to switch between three mutually exclusive modes -- insert, delete and navigate. That's because modern keyboards have keys dedicated to those purposes, which means the operator doesn't have to either wonder which mode he is in, or switch modes, which saves an enormous amount of time when programming. The first step toward modern editing is use of the arrow keys for navigation. The next step is to realize, if the arrow keys can reposition the cursor without using letter keys, then maybe there's no reason to have to switch modes. Vim's focus on keyboards that no longer exist, and on displays that no longer exist (including the paper terminal I used with vi while working for NASA forty years ago), requires an incredible number of unnecessary keystrokes, as exemplified in this typical conversation: http://stackoverflow.com/questions/1379198/in-vim-how-do-i-delete-a-word-and-go-into-insert-mode http://stackoverflow.com/questions/1379198/in-vim-how-do-i-d... Notice that no one says "have you considered solving the problem by changing editors?"
- xutopia 14y agoI 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 14y agoI 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 14y agoI guess I find myself hitting the wrong keys each time and I'm quite happy with ; being used for something else.
- marssaxman 14y agoIs there a way of typing which does not involve having one's index fingers on the F and J keys? I thought that home row position was standard (regardless of keyboard layout - I type dvorak but my index fingers still rest on the keys marked F and J).
- bilalq 14y agoThis 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.
- agscala 14y agoThis is okay advice, except that hjkl are actually useful occasionally. Disabling them will only hurt yourself.
- elbear 14y agoThe article says that. The title of this posting is a bit sensationalist, although it's used as a subtitle in the article itself.
- tompko 14y ago>I’m not really suggesting that you permanently disable the h, j, k, and l keys. ... But...If it forces you out of your comfort zone and encourages you to use wordwise motions, character searches, and other motions, then it counts as a useful exercise.
- manaskarekar 14y agoOne of the best (collection of) cheatsheets: http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial... The pdf version can be found here: http://www.glump.net/howto/vim_graphical_cheat_sheet http://www.glump.net/howto/vim_graphical_cheat_sheet
- TwistedWeasel 14y agoI 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.
- manaskarekar 14y agoIt is organized by types of cheats. It's more of a tutorial that aims to familiarize you with available features comprehensively. Once you kind of get an idea of what options are available, lookup is a little easier. This is definitely not the best cheatsheet for hanging above your computer, but more to be read as a tutorial. (Calling it a cheatsheet would be a stretch in this case.) For your purposes (and what I do quite a bit anyway), google is the best cheatsheet.
- pbarnett 14y agoI 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 https://github.com/MrPants888/vim_flashcards
- snambi 14y agoI use hjkl everyday. Its pretty handy. The arrow keys are too far away from the maon keys. Thats why hjkl is very useful
- pmelendez 14y agoI 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.
- aswerty 14y agoHe 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?
- dseigle 14y agoTo 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.
- falcolas 14y agoNo 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 14y agoFor 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 14y agoI was going to say. Disabling hjkl makes moving between word wrapped lines impossible
- erifneerg 14y agousing '/' (search) comes to mind. Drew also did an episode cover some more ideas and touches on relative number moving. http://vimcasts.org/episodes/long-range-line-duplication/ http://vimcasts.org/episodes/long-range-line-duplication/
- hboon 14y ago+ and - to move 1 line up. Combine with a number, 4+ to move down 4 lines, complementing 4G or :4<CR> to move to 4th line.
- falcolas 14y agoI don't see those as an improvement (i.e. worth committing to muscle memory) for `j` and `k` that would incentivize me to no-op those two keys. You can do `4j` as well.
- llimllib 14y agoIf you want to go to the same cursor position on the next line, definitely j is the way to go. Much of the time, I want to go to a specific part of the next line. In which case, let's say I want to go to the parse function, I'll do "/par<enter>".
- jlongster 14y agoIt'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 http://www.emacsrocks.com/e10.html). I use Emacs of course.
- bdc 14y ago> 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 14y agoI 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 https://github.com/goldfeld/vim-seek
- goldfeld 14y agoI'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 14y agosounds 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 14y agoYes 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.
- roel_v 14y agoLinkbait 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 14y ago>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 14y ago> 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.
- ken_railey 14y agoSo tap-tap-tapping on the arrow keys like a chicken is a more efficient way of navigating text documents then?
- 14y ago
- fnordfnordfnord 14y agoHard 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 14y agoThere is a vim tutorial baked in that will walk you through some things.
- fnordfnordfnord 14y agoIt isn't the first thing one sees upon starting vim for the first time, nor is it obvious in any other way.
- freehunter 14y agoI 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 14y agoI just freshly installed vi and tried that. Here's what I was greeted with. http://pastebin.com/HxvNP6Tr 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.
- deleted 14y ago[deleted]
- robomartin 14y agoOh 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!
- debt 14y agoWell now you're making me rethink everything.
- lynndylanhurley 14y agodude chill
- goldfeld 14y agoI 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..
- shmerl 14y agoI'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.
- kiwim 14y agoYou chose an awful title, nelstrom.
- dmbaggett 14y agoI 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 http://inky.com was make hjkl work to move around in the message list.
- hadem 14y agoSome 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 https://github.com/Lokaltog/vim-easymotion
- jodrellblank 14y agoIf 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.
- pmelendez 14y agoI 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
- redblacktree 14y agoTyping is not the bottleneck.
- saidajigumi 14y agoNo, 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.
- _nato_ 14y agothe 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.
- blinry 14y agoAnother 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.
- chatmasta 14y agoI'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.
- mieubrisse 14y agoMost 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!
- s00pcan 14y agoI 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.