On learning Vim

I’m sure Vim is going to be a wonderful thing for me to have learnt – a skill that will stay with me and benefit me for the rest of my life. It’s just getting there that’s so hard!

I started using Vim in earnest this week. On Monday i used Vim in the morning, and switched to TextMate when i got too frustrated. Tuesday was periodic switching between the two. TextMate when Vim got on my nerves, and back to Vim when i found myself missing Vim features. Yesterday and today i have been entirely on Vim.

Yesterday was great – i really felt i was getting somewhere, and gaining speed. It started to be less about me getting around Vim, and more about me doing my work. Today has been a bit more frustrating, as i know it is slowing me down significantly in the short-term, but i’m sure it will be worth it!

I keep finding myself smiling at Vim when i have elegantly told it to do something quite complex. It’s like “Wow, Vim, you’re so clever!” Selecting a block of text and duplicating it, going five words in and changing the text to the end of the quote marks: vapyP5wct" – said as “visual a paragraph, yank, Paste above, 5 words, change till quote marks.

It’s so cool to have Git integration right within Vim, and now that i’ve got the hang of the NERD Tree, and manipulating windows and buffers, i’m coming along a treat! I’ve discovered i have quite a strong perception of the layout of a project – without a project drawer i just couldn’t think what to do or where to find anything! I’ve also decided i really like side-by-side windows so that i can see code and spec at the same time. I’ll do a screenshot when i’m on my big computer.

The biggest problem in fact is not the super-amazing-cleverness of Vim and its plugins. I’m getting the hang of them pretty fast. The hardest thing is just learning the basic commands – like – moving around! I still get j and k mixed up, and it requires so much brain energy to remember whether i want to type a or i, o or capital O … even to remember to press <Esc> to come out of insert mode. Invariably i get it wrong and have to undo all the time. Either that or i’m undoing when i don’t want to, because i think u is for up. Fortuately i discovered on a Dvorak keyboard, k is underneath u so that sort of reminds me that k is up.

I just hope it is not my dyslexia making it hard to learn the basic movements. Most of Vim makes a lot of sense to me. I like that it uses mnemonics and mostly pressing one key at a time. I love how you can combine keystrokes in sequences to achieve really powerful effects. I hear that when you get really good at Vim you’re not even aware of exactly which keys you’re pressing. You just think about what you want to do, and your fingers do it automatically. I’m sure i can get to that level of proficiency … it’s just a case of being patient with myself whilst i’m still learning.

It was like this when i was learning Dvorak, but i’m glad i did, and my fingers do just type without my having to think about where the letters are. I type at around 80 words per minute, which is pretty nice, so i’m sure with the power of Vim, i could be truly awesome!

Advertisements

24 comments on “On learning Vim

  1. Vim was really designed for qwerty, and it doesn't really have “portable” key bindings. hjkl should be next to each other in order for vim to do it's magic. That's one of the greatest and easiest to see improvements with vim. You get to be really fast at trivial movements through your text.Anyway, here's a tip (i think it's from the vimtutor, you have gone through the vimtutor, right?). j is like a hand pointing down and k has this line that's bigger at the beginning so you could say it's pointing upwards. Also, h is at the left and l is at the right, but you're not using qwerty :)

  2. You know what, it's actually not too bad for Dvorak. The j and k are in my left hand, and h and l are in the right hand, happily the right way around! :DOne problem i have is that <C-F> is above <C-B>, which feels completely the wrong way around. But that's not even particularly intuitive on Qwerty either, heh!Yes, i have gone through the vimtutor a few times, it's good isn't it! :)

  3. I'm not totally sure I buy the whole hjkl thing. The version of vim I learned on had the arrow keys set up by default, and I don't think I've ever used one where they didn't work. I still use arrow keys for navigation (when I'm not using more vimmy motions like w, $ or regex search).I know hjkl keeps your hands on the home row – with qwerty anyway! – but it just doesn't seem worth the effort to me. I hate to think what it's like learning hjkl on a dvorak keyboard where they're not even adjacent *or* on the home row.

  4. I think it can be useful to learn the hjkl if you move around a lot of different keyboards where the arrows are in different positions. Or, a more meaningful example, the PgDn, PgUp. I've seen some keyboards where they are in really weird positions!Personally i'm trying to learn to use the motion keys just for the sheer geekiness of it … but you're right; it's not a disaster to switch to the arrow keys. Particularly if you're in Insert mode … i really think it is easier to use arrow keys sometimes, rather than escape out of Insert mode just to move up a line and then re-enter Insert mode.I'm just trying to work out when it makes sense to remain in Insert mode, and when to come out for the advanced movements.

  5. Free tips:1) imap jj <Esc>That way you can switch from insert mode to normal mode by pressing j twice. It's been a life saver for me (maybe not that useful on Dvorak though…).2) Try Vimperator.

  6. Great idea, thanks! I'll try that out and see how it goes.Vimperator is a truly amazing tool! Already i find myself struggling to use a browser *without* Vimperator.

  7. You can use <C-o> in insert mode to execute a command mode keystroke. To move up a line would be <C-o>k. This can be easily used in insert mode bindings to allow arrow-key-like movement on the home row while still staying in insert mode.I use these insert mode bindings. The first is simply deletes one to the right (H is move left in command mode, and Ctrl-H is the backspace character, so it made sense to make Ctrl-L the delete). The other two simply replicate emacs back and forward.imap <C-l> <C-o>d1limap <C-f> <C-o>limap <C-b> <C-o>hAlso it helps to get out of the <Esc> habit and use <Ctrl-[> which is the same thing but keeps your fingers where they should be, which makes jumping between modes less of a chore. <Ctrl-C> also quits insert but ignores abbreviations.

  8. Thanks for the <Ctrl-C> trick – i think i may well find that one useful. What do you mean by 'ignores abbreviations' – can you give an example?I need to get *into* the habit of escaping Insert mode when i have finished inserting, and *out of* the habit of pressing <Esc> every time i want to perform a command (“just in case i was in insert mode!”)

  9. When exiting insert mode with <Ctrl-C> abbreviations are not expanded as they would be with <Esc> or <Ctrl-[>.Make an abbreviation::iabbrev _C_for for(i = 0; i < imax; i++) {<CR><CR>}<Tab>Afterwards, if you type in the string “_C_for” in insert mode and press <Esc> (or insert a Tab), vim will expand it into the above for loop and put your cusor inside the brackets.However, if you exit insert mode with <Ctrl-C>, the abbreviation will not be expanded. Sometimes abbreviations turn out to be too clever, and you have to override them :)Personally I haven't got into the habit of using abbreviations yet. But if you find yourself creating the same coding blocks over and over its a useful tool. You can also use it to put in comment blocks with license/copyright on them.:iabbrev _license_GPL /* Huge GPL license comment goes here */

  10. Seems the blog ate some of my text, in the first abbreviation theres should be a bracketed Up command before the Tab.

  11. Ah, this sounds like what i know as 'snippets'. I do use a few snippets, so i'll remember your reply if they don't work.I am grateful for the Ctrl-C trick – it works well for me. I covered up the Esc button this afternoon to get me out of the habit of pressing it more often than i need to. The Ctrl-C is good because if you press it too many times it gives you a message about how to quit Vim! That's like a little slap wrists to me: “Don't be silly – you weren't even in Insert mode!” :)

  12. I mapped my caps lock key to escape using xmodmap. Trythis from the command line (obviously you have to havexmodmap installed)xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'I find it makes vim a lot easier to use.

  13. Finally a person with the same “problem” as me!I started out with Vim a few weeks ago (OK, I've been using Vi(m) for years, but it's been more 'press a, navigate with arrow keys and insert some text, press Escape, type :wq'), and I'm liking it the more I use it.I use the imap jj <Esc> tip, and it works pretty good, despite me typing in Dvorak. Since I often want to navigate down when going back to command mode, it's a good reminder which is up/down. Also, playing Nethack helps (or at least is a good excuse for having some fun).Now to the main point. I also use a Typematrix 2030, and while I love the keyboard, I sometimes miss that useless Caps Lock to the left that I can map to Escape. The jj combination doesn't work all the time, for example when using Vimperator. So if you find a good key to map as Escape, I would love to hear it.My current layout looks like this – http://hanswchen.files.wordpress.com/2008/04/sv… – so there isn't much space for an Escape key. I've been thinking about buying the new USB version, and maybe map the “Play” button to Esc, or maybe the “Caps” key. Though it would probaby feel pretty weird to press Esc with my right pinky.By the way, to you have the Typematrix USB version? I have some questions regarding it as well.

  14. Oh awesome! Vim + Dvorak + Typematrix = WIN!I've found that Ctrl+C is the best way to exit insert mode. I didn't get on very well at all with the jj combination.What is the 'play' button? It is source of great distress to me that 'app' and 'shuffle' are ignored by OSX. I used to use the shuffle key all the time in Windows.I have the PS2 version of the Typematrix 2030 with the USB converter that they supplied with it. Although i've started using the new Apple keyboards which are even smaller and flatter than Typematrix. Still the Typematrix is extremely useful for pair programming, thanks to its hard-coded Dvorak.Please tell me more about how you are using the Typematrix. I'm quite excited to find someone else with such similar experiences to mine! :)

  15. I'm glad that you responded – when I wrote my first comment, I didn't realize how old this blog post was!The thing I like the most about Typematrix is that the keys are in vertical columns. I couldn't touch type on 'normal' staggered keyboards before I got my netbook, and I never bothered to learn, because it seemed so dumb. Why make it so hard when it could be so easy?Regarding 'shuffle' and 'app', maybe the USB converter is to blame? I've heard that it had some quirks. All keys work fine for me, and I use Linux + PS/2 connection.If you look at my layout (link in my first comment), you can see that I've heavily customized the keyboard. I added 'ÅÄÖ', which are used in Swedish, with the unfortunate consequence that some other keys had to be moved elsewhere. I also added symbols to most Alt Gr-<Letter> combination, which means that I don't have to move my fingers so much when programming.This also rocks in Vim (although it wasn't my intention when designing the layout) – for example, : (colon) is Alt Gr-H. If I want to save the file from insert mode, I simple press jj Alt Gr-H w Enter.OK, this probably sounds silly to 'normal' persons who're used to Ctrl-S, but it's actually pretty fast – and there's so much more. If I want to search, I press Alt Gr-O [type word] – again, I didn't have to leave the home row (I press Alt Gr with my right thumb).To change my keyboard layout, I use something called xmodmap (on my netbook, I created a new xkb layout instead). I don't think you can use these methods in Mac OS X, but I'm sure there are other ways to obtain the same result.Oh, and I also changed the position of Alt Gr (maybe I should mention it – it's the right Alt in some country layouts) and right Ctrl. The default positions were almost as stupid as the QWERTY layout! ;)(No offense to you QWERTY users).Some time ago I mailed Typematrix and asked them about their new USB keyboard. Their answer was:”In any case, and unfortunately, the lower row shift has the same scan code as the left shift, so changing one will change the other. That was a major oversight in the last model, and it has been corrected in the USB model that is coming. All keys on the new model will have different scan codes so that you can rearrange the keys quite easily.The “Play” key works with the Media players and starts the music. If your media player is not engaged, that key will not do anything, and you will be able to reprogram it to Start, or anything else. That key is placed especially for the European languages which have an extra key on their keyboards, and that key gets activated in those languages. This new keyboard will work with all languages in the world, including Japanese. There is no other keyboard that can do that.”Yep, I also wanted to swap the left Alt and bottom left Shift, but it's not possible without affecting the other left Shift. To my delight, they've fixed this in the new USB version – and almost all other issues I have with my current Typematrix! I'm just I little afraid that you can't remap some of the special buttons. According to the person I mailed it's possible, but I want to make sure before spending $110 (actually, it's probably more expensive in Sweden). If I can confirm that there aren't any problems with remapping, I'm going to get the USB version as soon as possible – there are only advantages in my opinion. You can see the new default layout here: http://www.typematrix.com/images/bepo/2030usb_u…Puh, that was a long comment. Hope you didn't fall asleep reading it all. :DJust a final word regarding Vim: I don't like the Ctrl-C combination, since Ctrl is almost as far away as Escape (and hitting one key is easier than hitting two). I'm thinking about just sticking to Escape, as1. It's not _that_ far away on the Typematrix. I can even reach it without leaving the home row.2. Once you get used to it, I don't think it's that bad (on the Typematrix, at least).On the other hand, I like the jj combination too. Maybe I can learn to use that to escape insert mode and escape for the other cases?Looking forward to hear your experiences with Vim, Dvorak, Typematrix and everything.

  16. Oh sorry, i assumed that was the Swedish Dvorak layout.Hmm, i really don't like the new Typematrix layout. It just seems very different, for no apparent useful reason. I should hope the keys are easily configurable – who wants a hard-coded calc, mail or www key?I have to confess, i've started using Ctrl+S on MacVim (and Gvim on Linux). I have a bad habit of always using the left-hand shift key, and using the colon key so much was giving me RSI troubles. For that reason alone, your colon key re-map looks useful! I am trying to re-train myself to use the other shift key when appropriate. I'm probably about to write a little blog post about that.I think i might find a way to make Ctrl+S take me out of Insert mode (it works in both modes). It seems to be my expectation that it would do that.What kind of a netbook do you have?

  17. I agree that the extra buttons (Calc etc.) on the new version aren't very useful, but for me it's far better than the current layout; backspace can't be remapped without affecting the backspace in the middle, and Fn isn't remappable at all. Two completely useless keys on my keyboard.However, I think I'll keep Delete where it is now, to the right instead of in the middle.Regarding Shift and Ctrl, I press the modifier key with the other hand: if the letter is on the right, left hand holds down Ctrl, and vice verse. This is also something I taught myself when I decided to learn Dvorak – before I only used the left Shift and Ctrl.I've been thinking some more about the Escape key and decided to get rid of the jj mapping. I think I'll go with the Ctrl-C way despite what I said earlier – it's standard in Vim, so I won't find myself inserting lots of jj on someone else's computer. And with the new Typematrix, left Ctrl is nearer to the home row which means that I don't have to move my hand that far to press the combination.My netbook is a Samsung NC10, a very nice machine. However, it's in for service at the moment (the 'o' key was less responsive than the other keys).

  18. Thanks for the post Aimee, nice to know I'm not the only one pootling along with Vim. One question though: which guide are you using?

  19. it doesn't really have “portable” key bindings. hjkl should be next to each other in order for vim to do it's magic. That's one of the greatest and easiest to see improvements with vim. You get to be really fast at trivial movements through your text.

  20. Personally I haven't got into the habit of using abbreviations yet. But if you find yourself creating the same coding blocks over and over its a useful tool. You can also use it to put in comment blocks with license/copyright on them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s