Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Snake Vim Trainer (vimsnake.com)
109 points by zachgersh on Aug 16, 2013 | hide | past | favorite | 69 comments


When I was learning vikeys, I just disabled arrowkeys in my .vimrc :)

    inoremap  <Up>     <NOP>
    inoremap  <Down>   <NOP>
    inoremap  <Left>   <NOP>
    inoremap  <Right>  <NOP>
    noremap   <Up>     <NOP>
    noremap   <Down>   <NOP>
    noremap   <Left>   <NOP>
    noremap   <Right>  <NOP>
I know it sounds masochistic, but it really isn't; I actually had to check after a while whether I really set it, because I didn't remember any issues with navigation. Try it!


I was about to say that the keyboard controls didn't work for me until I remembered that I had Vimium installed with Chrome.


Same for me, too. Also disable Vimium if you have RES installed.


ditto


I certainly like VIM, it's my default editor on non-Windows operating systems, but I really don't care one bit about the h,j,k,l keymapping; I can use my arrow keys, which I find to be lots easier. So I TOTALLY suck at this game because it doesn't support the arrow keys like VIM does! :P


You're missing a ton of vim's value by doing that. The reason for those key mappings is so that your hands can remain in standard "typing ready" position, so that you can both type and navigate without moving your hands. If you are moving away to the arrow keys, at that point you're one step away from just navigating by mouse: it's really missing the point.


I don't know about "a ton" -- there are far better ways to move around a file than mashing hjkl, even with numbered versions (vim-easymotion, vim-seek). Once you can get to the right place in the file I almost never use hjkl with an action, but rather text objects or motions like ci" or dt;


I've started to use relative line numbering (numbers.vim is highly recommended) and that has made me use 'j' and 'k' in motions quite frequently. I wish I had made the change earlier!


Just to state some support for this: I have used vim for over a decade and I haven't used hjkl on a good day once. Arrow keys are fine.

Occasionally I use hjkl if the terminal is set up wrongly or it's a broken vi implementation but that's it.


Interesting. I'm curious as to how and what you use vim for. I find it hard to believe that anyone would seriously do something like d + down arrow with dj available. All of those seconds (it takes me more than a second to go to the arrows then back to home row) add up over time.


You would use 'dd' instead which is faster since you don't have to have make sure your other hand is in the correct position.


My example involved deleting two lines, which you can accomplish with '2dd', 'dj', 'dddd', etc. When my hands are on my keyboard 'dj' is my personal preference. The parent poster was using arrow keys so naturally I'm wondering if for something like 'dj' he/she would use 'd + down arrow' since that seems like waste of time. It's a somewhat contrived example to see how far some users take the use of the arrow keys, which you quickly realize are not necessary in vim.


It depends on your keyboard as well. I use a Kinesis Advantage, which has the arrow keys in a place that doesn't require movement from your hands, so hjkl doesn't provide the advantage that it used to.


I have a ThinkPad. The keys are closer together.

Used for most editing tasks. Those seconds are fractional compared to thinking time before cutting code. I'm not paid in words per minute.

w, g, / are used more than the arrows anyway.


This should get you comfortable with using the h,j,k,l mapping then. I actually turn arrow keys off in my vimrc, I can definitively say it is one of the things that has made me faster.


Do not turn them off; remap them! That is valuable keyboard real estate.

I use them for buffer switching, since I do that frequently. Left and right change to the next and previous buffers, respectively. Down to quickly swap to the previously focused buffer. Up to bring up a buffer switch menu. Here are the .vimrc lines:

    " Arrow keys for buffer switching
    nnoremap <left> :bprev<cr>
    nnoremap <right> :bnext<cr>
    nnoremap <down> :buffer #<cr>
    nnoremap <up> :buffers<cr>:buffer<space>


Such a good call! I don't use buffers enough :)


Great tip!


Good point about using this to get me comfortable with the keymapping. I dunno if I'll get too depressed from dying over and over before I get the hang of it though! ;)


Getting frustrated and depressed with keymapping? Sounds just like my experience using real vim ;)


I got the pitch forks, who has the torches?


The game is fun, but perhaps a bit misleading regarding what 'mastering vim movement' amounts to. As I am sure many of you know, vim has tons of constructs for efficient navigation: Using b or w for word-wise jumping, special markers like $ and 0, Ctrl-D and Ctrl-U etc. A good overview of movement commands can be found here: http://vim.wikia.com/wiki/Moving_around


Right. For it to really feel like vim movement, I'd push two keys and the snake would jump to the next food pellet in insert mode...


I made this site at Dev Bootcamp Chicago. It's super simple, but if it brings someone any amount of entertainment, it'll make my day.

The snake part is a HTML5 canvas, and the back end is Ruby/Sinatra.

Enjoy!


This is awesome! You should add ctrl+[ as an alias for escape as vim does. I've used that for a while now, and actually reaching up for escape feels unnatural now.


I was thinking the same thing. Not being able to use ctrl+[ actually made this game really really hard for me as my muscle memory screams in protests each time i want to exit insert mode.


Ctrl+[ isn't an alias for escape, it is escape on traditional terminals (and a whole lot of terminal emulators). It's useful to know this when using a keyboard that lacks an escape key.


Thanks for the VIM tip! I never even thought of looking for an alias for esc before.


I aliased jk to ESC. Can that be added in?


Out of habit I used jj to escape. A touch of inoremap would help this game :)


did this recently and it's been very useful. if anyone's interested ('kj' is faster for me), add to ~/.vimrc:

inoremap kj <ESC>


Easy! I'll add this today


why don't you map escape to caps lock?


This is what I do too. Caps lock is a mistake anyway. The keyboards vi was written on had ESC where the tab key is on most keyboards now[1].

[1] http://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg


And if you're one of those skeptics that thinks "but I sometimes use caps lock to type C_STYLE_CONSTANTS, and I need it!", there's a wonderful thing I call two-shift caps lock: you press both shift keys at the same time, and it toggles caps lock. Now you have your Shift keys, and your caps lock, and a key that really truly has no purpose. Now go forth into the world, and remap thy keyboard.

In GNOME: System → Preferences → Keyboard; Layouts; Options; Miscellaneous compatibility options → "Both Shift-Keys together toggle Caps Lock" (You can also remap Caps Lock in this same dialog, so the change isn't just for Vim. It's under "Caps Lock key behavior". Also, having a compose key is awesome.)


Is there a way to do this without installing addons to vim?


I find I'm having a mental conflict between Vim's hjkl controls and WASD-style gaming controls, despite having very little experience using the latter with my right hand. This is made worse since it happens to be 'i' that my right-hand middle finger hits when I think "go up".

Very neat though, regardless!


This is what is preventing me from learning Vim. I play games every day using WASD movement and if I have to switch to hjkl my brain goes haywire.

I have been waiting for someone to create a Vim control scheme that relies on WASD movement and maybe also brings in other common gaming related keys (E for insert?, space for escape?) To me this seems more logical than hjkl/i/esc.

Until then though it just feels like more work that it needs to be for me to personally learn Vim. Which is a shame because I can recognize how useful it can be, especially after watching Destroy all Software screencasts.


I do both regularly. They are different hands and the different movements actually become very different feeling. When my right hand is on the mouse, WASD feels natural. Otherwise, I naturally hold my left hand near the ESC key and my right hand over HJKL.

Because it's the home row, it also feels more natural when you are getting ready to type. The mental separation between "gaming" and "typing" is not hard to get a hold of really quick. Give it a try! I guarantee you'll be completely used to it within a week.

Also, keep in mind all of these keys can be remapped in Vim anyways :)


It seems like that person I have been waiting for to create that mapping is me!


I had the same issue. Here's my config to solve it (ijkl become like arrow keys, h is insert instead):

    map k g<Down>
    map i g<Up>
    map j <Left>
    noremap h i
Note that with this config, we maintain the normal mode "inner" text objects with "h" instead of "i". So where you would previous type di' to delete inside quotes, now you'll dh'. And dh( instead of di(, etc. It all works, and I've been using this config for a couple years now.


I just tried the sname game and had the same experience (although I use ESDF for controls). My brain is not used to using my right hand for directional control.

That said it should be easy to remap vim keys to use WASD/etc - although there might be conflicts with other functions.


Having the same mental problem myself, even with a decade or more of both esdf and hjkl, and I'm now wondering if I should or could switch i and h -- switch input mode to h.


You can, please see my reply to your parent.


It's left hand vs right hand, though.


This is awesome. I thought I was pretty good at vim, but the added pressure of needing to switch modes and directions at the same time without thinking about the keys was a great learning experience! (and fun game too!)


In light of the recent comments about mods editing article titles, I gotta say that when I saw this earlier today I didn't think it sounded interesting. After the rename, I clicked on it, and man, it's awesome.


vim and BSDs default configurations insisting on inexistance of arrow keys is a "tradition" not completely unlike clitoridectomy. Come on guys (and gals), we've been over this already.


It is not insisting. Vim will happilly let you use the arrow keys. It's just that once you acclimate to "hjkl", it is slightly faster and more comfortable, since you don't need to move right hand anywhere while typing. Or at least that's how it works for me.


It is completely unlike that, please don't compare not having arrow keys to genital mutilation.


There's a thing called perspective that you may want to consider exploring. Remapping the arrow keys is a minor annoyance at worst.


What? The arrow keys work fine. They're just waaaaay over there. Why do you want to use them?


They're rather waaay on my keyboard where my right hand is.

What I'm talking about is deliberate crippled default configurations.


As I recall being forced to use the homerow in typing class was just like being circumcised.


Your terminal is probably not correctly configured. Remember that real terminals did not originally have arrow keys or home end keys or really anything that's not in ASCII. If you're actually using a termcap old enough that it doesn't know about those escape sequences (maybe Solaris and other commercial UNIX offerings), or you're using a more recent termcap but your $TERM is set to something ancient, then the escape sequences are not interpreted.

Of course UNIX terminal handling is not standardized at all, so you may find that some programs ignore $TERM and do their own thing.


$TERM is a joke when you're on ssh (and that's always). It's always "xterm" but there is a huge variation between those xterms and key codes seems to be altered as they pass down the chain.

Is Home ^]]1~ or it's ^]H? You have to guess every time.


You can use the arrows in vim by default, no problem with that. For example, all my current co-workers use vim and I'm the only one who navigates using HJKL. With that said, I really really recommend any vim user to at least give a shot at using it instead of arrow keys. YMMV, but for me, not having to reach for the arrows help me stay in the zone.


Some distros/OSes ship with unmapped arrow keys and broken home/end in the terminal. This is seriously bad for your health.


On Firefox, It just goes right through the "food"


You have to be in INSERT mode (press i) to eat the food. That catch is that you can't change direction in INSERT mode. Press 'esc' to get out of INSERT mode.


That's what insert mode is for.


A good way for me to learn movement is to think of direction as:

walking up stairs: kl kl kl kl kl kl kl walking down stairs: jh jh jh jh jh jh jh jh jh


I played Nethack on a MacBook Pro (with no number-pad) to get used to the vim movement keys.


I use vim everyday and I don't find this game easy to play.


robots, and later nethack, served this purpose for me as a child... likely less effectively.


topscore never seems to update.

Try `$.post('/newtop', {score: 16000})`


leaderboard doesn't appear to update (at least in real time).


you just had to go with something different than WASD didntcha?


That game is impossible




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

Search: