Why, oh WHY, do those nutheads use vi?

I’ve written an advocacy article… well, no it’s not advocacy… well, YES, it IS an advocacy article, about vi/vim editing. The main goal is to have an explanation so that NON-vi(m)ers can understand what the fuss is all about, and why me, and many other thousands of people (including all my customers) still use vi/vim, and (at least my customers) go as far as paying me $70 for the privilege if they happen to use Visual Studio, Word, Outlook or SQL Server. Many of them even deem it a bargain.

Without further ado:

Why, oh, WHY do those #?@! nutheads use vi?

Enjoy!

143 Responses to “Why, oh WHY, do those nutheads use vi?”

  1. Mark Says:

    Great article.

    I remember learning vi over 15 years ago (using hjkl on a vt100 terminal no less), and I hated it for the first couple of months.
    But it’s true. Once you ‘get it’, you’ll never go back.

  2. Kevin Says:

    There is even a vim plugin for firefox: http://vimperator.mozdev.org/. I agree that the editing commands are absolutely indispensable when editing. Thanks for the great post!

  3. Greg Says:

    Great article! Can’t believe I’ve used vi for so long without using the . trick :-)

  4. Hernan Says:

    Great article! A couple nits:

    1) In the 1st example, you are not deleting the semicolons at the end of lines 2 and 3. I think you should delete the semicolons first, perform the A command second.

    2) In example #2, you can use the p command to “put” the contents of the buffer back into the file. No need to use Ctrl-R which is a vim-only command :-)

    I use mostly plain-vanilla “vi” most of the time; but your article convinced me to go and take a look at all the additional “vim” commands.

  5. Rob Says:

    What I can’t stand is the nutheads who use vi but can barely use it. They append to a line by using the arrow keys to get to the end of the line, then type i, then type the right arrow. They add a new line by using the arrow keys to get to the end of the line, then type i, then type the right arrow, then press enter.They revert back without saving by quitting vi and starting it again.

    Watching this makes me want to go jump out of a window.

    I wish some people would go back to using Notepad.

  6. Brian H Says:

    VISEARCH.COM !

    VI + Web Search = http://VIsearch.com
    Powered by and created by Snap.com

  7. Marv Says:

    Great article. I’m a committed Vimhead, and I’m only using it to compose text and write the occasional Python or bash script. I can’t begin to imagine the near-biblical power it must hold for the true coder. Modal editing in itself was a revelation for me when I made the switch from lesser editors. Thanks!

  8. Phil Says:

    You’ve almost converted me. When I heard about software to emulate vi I thought people were crazy… vi is only what I used on locked down systems, or until I got emacs installed. But I see now it’s a shortcut junkie’s best friend, great article!.

  9. Geoff Moller Says:

    This is among the best Vi/m advocacy articles I have read - well done.

    …if you’re going to be editing code 8 hours or more a day for years, it’s the second best investment after learning touch typing (which you already know, right?…

    I think you could expand on the touch-typing prereq - without it, learning Vi/m is even more agonizing.

  10. Penguin Pete Says:

    Speaking as a life-long Emacs user, I just wanted to say: I like vi too! It was a challenge to learn either one, but when I’m dealing with a system where Emacs isn’t viable (i.e. too big), the smart, compact vi editor does just as nice a job.

    This article has opened my eyes to new tricks I didn’t know vi could do! Thanks for the great tutorial!

  11. J Says:

    Thanks a lot to all of you for the great comments.

    Hernan: (1) at least in vim, ‘.’ repeats the too, so no need to do anything beyond using ‘j’ to position yourself in the right line, and pressing ‘.’ to do the whole operation. And (2): Ctrl-R,” allows you to enter it while typing the declaration - you have to type the variable type and the semicolon by hand, so addding the paste in the middle is just more comfortable. “bool varname = ;P” would do it, too, but it’s more awkward for me.

  12. Tim Says:

    Your article is much prettier than mine. I should learn to do more screen shots and stuff. I am saying a lot of the same things, but they’re prettier on your page. ‘hi tim guifg=jealous’

    http://tottinge.blogsome.com/use-vim-like-a-pro/

  13. J Says:

    Hey Tim. Doing screenshots is a huge effort, it took hours. And we humans are mainly visual beings. I saw your page, it’s cool, but it’s too dense. Well, it will be more useful than my article for someone who is actually putting the effort to learn, but most people are before that stage. After my article, people would do well to visit your tutorial for actual means to learn. I just showed the nicest features in the most immediate way.

  14. Mr J Says:

    You realize that the “VI Gangsign” is the shocker.

  15. Marv Says:

    Speaking of screenshots, you may or may not be familiar with Michael Schwarz’s ScreenShot script for Vim, which generates HTML depicting a non-image “screenshot” of Vim’s current window, with color scheme, formatting, syntax highlighting, etc. intact. The results look like images, but aren’t. It’s really quite a brilliant thing if you have need of Vim screenshots but don’t want to mess with images.

    http://www.vim.org/scripts/script.php?script_id=1552

    I hope you won’t mind the plug. I’m not “shilling” or anything; I just thought it might be useful.

  16. Sridhar Iyer Says:

    Nicely summed up.. ever typed i or :wq on a non-vi editor?? I desperately need a vi plugin/greasemokey for my firefox textboxes.

  17. kevin Says:

    I must say a counter-argument here, which I saw repeatedly to be true: people in fact can and do master very bad systems (whether they be editors, frameworks, etc). Once they mastered them, for these people these are no longer bad systems, but very ‘useful and effective’ tools. I think you can think about this for a moment.

  18. Dave Says:

    I just wish there was an easy answer for us dvorak people, hjkl are moved from the home row. Maybe there could be a Dvorak-Qwerty mode (like on my Mac); when in insert mode you type in Dvorak, but when in command mode it works in qwerty.

    Also, I’d love to move the movement keys to the right by one key so they lay under the resting spot for the true touch typist.

  19. Igor Stirbu Says:

    One should use ‘=aB’ for indenting a block. ‘>aB’ will just shift to the right the whole block and it’s not ok when some lines should be shifted to the left. Thanks for the article.

  20. J Says:

    Ok, I’ll prepare a two-handed version of the “vi gang sign” to avoid connotations, as done here:

    http://www.flickr.com/photos/x180/473801152/

  21. Jim Says:

    I’ve used vi a bunch, but I don’t “get it”.

    What about refactoring tools?

    I’m an IntelliJ user and I can do a bunch of refactorings that save me tons of time. Does VI have an answer for them?

    For example, extract method, extract interface, Alt+Enter to create methods, Alt+Enter to add imports, live templates, ctrl+alt+t surround with try/catch and other block types.

    IntelliJ can leverage knowledge about java class structure to do those refactorings and macros. Can vi do that? I doubt it. I don’t know everything, so I’m leaving myself some wiggle room.

    http://www.jetbrains.com/idea/training/demos/overview.html
    (everything this shows is keyboard driven as far as I am aware)

    Oh, and it has C++ plugin too: http://plugins.intellij.net/plugin/?id=1373

    No I don’t work for JetBrains, just LOVE Intellij IDEA!

  22. Waz Says:

    “Using vi/vim properly, you don’t use it modally. You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press to go to normal mode.”

    You don’t use it modally, here’s how you change modes.

    Got it.

  23. J Says:

    Jim, I believe vi editing + a powerful IDE are the best. They are not exclusive. I use Visual Studio’s Intellisense along with vi/vim editing. I’m looking forward to even more powerful IDEs. Your comment is spot on, but I don’t take it as “anti-vi”.

    Waz: well, I possibly didn’t explain myself well. Technically, it’s of course modal. But even regular editing can be seen as technically modal: having shift pressed means “extend selection” for navigation keys. The mode is not “sticky”, though. I should have possibly made that clearer in the article: it’s technically modal, but mode changing is only used for a short burst of typing, rather than staying in it. Most people who come to vi think one would spend most time in insert mode while going back to normal mode some times, and that’s the mistake I was trying to address.

  24. Jim Says:

    >I believe vi editing + a powerful IDE are the best

    Fair enough. Combine vi editing with IntelliJ and you get the IdeaVIM plugin. I’m to the point where I don’t think I want to re-learn vi. I never use it enough to have it stick in my muscle memory (more than how to delete lines, switch modes, and save). I’m too lazy I guess.

    >Your comment is spot on, but I don’t take it as “anti-vi”.

    Right, not anti-vi, just anti-people-who-are-religious-about-tools (or OSes). I once had a professor that claimed: “I can get more done with vi and latex to do publishing than anyone with one of those WYSIWIG publishing tools!” He was probably right — back in the computer stone age he learned vi in. “Latex” might not be what he said, but insert whatever PostScript tool makes sense there.

    I love IntelliJ, but I (hopefully) don’t preach it like a religion. You don’t seem to be a priest of the holy vi, just an advocate. Nice to know there are people who are not nutters and use vi.

    I still use vi occasionally on *nix systems when I don’t know what editors are available and don’t care to find out or wait for KDE/Gnome to load.

  25. Craig Kim Says:

    vi may not be suitable for all editing needs but is the best editing tool for program source code regardless the language. As Jon pointed out, a typical programmer would spend about 90% of time moving around and 10% inserting new text. If so, doesn’t it make more sense to be in the command mode most of the time? Having the two modes is actually a blessing! You can accomplish so much more because of these two modes. Most of the editors which are always in the insert mode cannot do so. You have to use special key combinations, mouse, or function keys to accomplish seemingly simple tasks, forcing you to move your fingers off of the keyboard.

    Yes, it does take a bit of time to learn it but once you’ve done so, you will see that your fingers will do most of the work for you without having to lift them off of the keyboard to use the mouse just to accomplish a simple task. Learn and you will never look back.

  26. Curtis Says:

    Your example #1 only works* in vim, and only then when the backspace option contains ’start’. This might be the default setup in the typical Linux but not everywhere. I never use vim configured that way, although your example gives a reasonable use case that requires it.

    * That is, the initial backspace after entering insert mode via A to delete the semicolon.

  27. J Says:

    Jim, I understand not everyone can put in the effort to learn vi, but I still like to help inform them what they are losing. If only so that they won’t look at us like we’re nuts.

    Craig, you raise a point that I didn’t go into in the article. When editing code, you’re moving around most of the time, so a specialized tool that doesn’t lose most of the keys to typing makes all sense.

    Curtis, I use gvim in Windows, and it’s always behaved like that. I implemented it like that in ViEmu, too. I only recently learned about the :set backspace setting. In any case, I think it makes sense to give the backspace key the most power, don’t you think?

  28. chuck Says:

    Gah! I *really* want that vi emulator for Eclipse, but the site seems to be down. Anyone know for sure if the plugin is still available, and does it work with Eclipse 3.1?

  29. J Says:

    The viPlugin site was up yesterday, so it’s probably just a matter of waiting until it comes back.

  30. Erlend Helmersen Says:

    Very good article! ViEmu is the single most useful software released IMHO. I only wish you did not publish more article like this, I dont want anyone else being as productive as me. Let them use their crappy editors with all their Ctrl-C, Ctrl-V or the ever so powerful Ctrl-H! I have tried Esc-Meta-Alt-Ctrl-Shift (Emacs among friends), but vi will forever be my choice. Once you have driven a Ferrari, you will not go back to a hatchback.

  31. J Says:

    Erlend, thanks for the kind comment. I will keep publicizing vi editing though :)

  32. myspace Says:

    Thanks man! I used to be an emacs “user”. Isn’t confession one of the twelve steps to accepting you have a problem? Anyway, A kind friend introduced me to vi and I can’t go back ever. Long live VI!! Thanks for the great article!

  33. yebbey Says:

    Nice answer to question that I have also asked after being face-to-face with vi when there is no other editor available. Your article motivated me to give at least few weeks for vim to show its capabilities! :)

  34. Jay R. Wren Says:

    I’m a long time vi/vim user. In fact I hate it when I’m on a system without vim. I find old vi to be inadequate.

    My biggest concern with vim as a Visual Studio editor is “what about my intellisense. I’m not willing to give up intellisense for what vim offers me. Does intellisense work? Am I believing in a myth?

  35. J Says:

    Hi Jay,

    If you’re concerned with how ViEmu works, the easiest is to download it and try it out. Intellisense blends perfectly with vi editing - it only kicks in in insert mode, the ‘.’ command can repeate Intellisense-autocompleted input, etc… In ViEmu/Word&Outlook, orthography/grammatical autocorrection and autostyling (auto-smart quotes, ‘…’ ellipsis, etc…) work in insert mode, etc…

    Myself and many hundreds of users use it every day, and, for vi-lovers, it’s a lifesaver.

    Cheers,

    Jon

  36. Gilbert Mark Stewart Says:

    I have always used vi and will continue to. When will this tool be available so I can use VI keystrokes in MSword on the Mac in OS X?

    Mark

  37. Mario Says:

    Sridhar Iyer, you can use vi/vim to edit text areas in Firefox. Look into It’s All Text extension for Firefox that lets you specify external editor. I,m typing this in gVIM :).

  38. J Says:

    Hi Gilbert, I’ve had a few requests for a Mac version, but unfortunately it’s not in the plans right now. I might do it in the future, but ViEmu/Word&Outlook is too tied to the Windows platform for it to be an easy port.

    Mario, I’d love to have vi keystrokes right inside the browser - an external editor is always less comfortable.

  39. zoice Says:

    This is such a great article, thanks for it.

    I’ve learned quite a lot of things, especially the i command (yi(, yi[, …) and f are wonderful!

    This could well be the article to convert some long-time regular editor users to vim.

  40. Ross Says:

    Is it possible that Vi lovers are the way they are simply because they had to put so much effort into learning how to use a text editor?

    Before someone bashes the heck out of me, yes I know it’s more than just a text editor it’s the greatest thing since sliced bread. I still prefer pico.

    Regardless, thanks for the interesting read.

  41. zoice Says:

    Although that’s maybe valid for some, it’s not very likely. It’s actually quite dumb to use something that slows you down and gives you nothing in return and i can’t imagine that’s true for so many people.

    Learning Vi(m) takes not _that_ long, took me about a month to get fluent, and from then on maybe a few more months to get really proficient. Thats almost always overwhelmed by the long usage period afterwards, which ranges from years to tens of years.

    It’s not that it takes long to learn basic Vi editing, after a few days you’ll reach your former editing efficiency easily, but from then on it takes some time to use Vi really effectively.

    Many other text editors just don’t offer that much flexibility and control, and that’s why you can use them right away. But you won’t get the same efficiency out of them as you can get out of Vi.

    Of course, if your current editor suits your needs and you feel comfortable with it, theres no real reason to change your tools. But understand that many Vi users didn’t think so of their former text editors and tried Vi with it’s steep learning curve, and the fact that most long-time users love it should make clear that it can’t be that bad once you’re into it.

  42. J Says:

    Ross, I hope the article is a better explanation than that :)

    zoice, I agree on your points. I feel that only emacs is a contender at the same level. And I also think there is a huge gap for a new editor, which I’m working (the tentative name is ‘kodumi’). Hopefully, I will release 1.0 some time during this year. Ah, with great vi/vim emulation, of course!

  43. squaint Says:

    I’m not a programmer, but a long-time Unix sys admin. I’ve managed all manner of *nix boxen in the last 10 years, and no matter if it’s Solaris, HP-UX, IRIX, Linux, or AIX, things usually start with ‘export EDITOR=vi’. When I am forced to use some behemouth application to write a four-line email, there are usually several h’s, j’s, k’s, l’s, cw’s, x’s tha need dw’d before I can click send. Vi/Vim is always there. It always works. Great article. Thanks.

  44. trans Says:

    I’ve used vi for quick edits for years now, and in all that time I’ve never come to like it. I’d rather recall a handful of key sequences that I can reuse for many situation, even if it takes me a couple extra seconds to execute, than learn hundreds of cryptic code combinations. Granted there’s some correlation between the letter used and the concept (B for block) but that’s not perfect and requires dozens of “letter clues” to recall too. So >aB does what? I use Shift-Down a few times and then Tab. Easy. To me it’s the difference between drawing a picture and describing it. Yes, a concise description can do wonders, but it can also easily SNAFU real quick like. When using vi I’m constantly correcting errors. Oops I’m not in insert mode. Oops I hit 55 rather than 5 –okay hit u, oops i’m not in insert mode again. **k. I find myself hitting the ESC key twice just to be sure. And that’s the other thing. You always here about the great hjkl keys so you don’t have to move your fingers, forgoing the Dvorak issue, my left hand is still always moving to the furthest upper corner of the keyboard to hit ESC so what’s the point? To me that’s worse. I’m used to using th arrow keys to move around. No other program except vi ever uses ESC constantly.

  45. burrowingowl Says:

    This article led me to give vim a try again after using emacs and jEdit for years. I’m converted. Never looked back. Thanks.

  46. J Says:

    burrowingowl: great! I’m very happy to hear the article convinced you to give vim a try. If you put in the required effort, I’m sure you won’t regret it. Thanks for letting me know!

  47. ikk Says:

    Since i already know many vim tricks, i would like to find a similar article about emacs… The only thing i remember about emacs, is that Backspace (ctrl+h) opens the help and save (ctrl+x ctrl+s, i guess) has a ctrl+s so it locks up the terminal :-P (until you press ctrl+q, which may be another command)

    PS: “kodumi”… is this an Esperanto name?

  48. J Says:

    Hi Ikk… unfortunately I can’t be of help with emacs.

    And yes… kodumi estas esperanta nomo :) It means ‘hacking’ in Esperanto. I liked the sound, too.

    Congratulations, it’s first time someone identified the source of the name!!

  49. Sven Says:

    thanks for this excellent article. I’m a converted (x)emacser currently taking the steep curve and slurping articles with good tips or summaries.

    Thanks again,
    Sven

  50. Tom R Says:

    Just to comment that I used vim full time between 1994 and 2000, both for writing papers in latex and for writing codes, but was forced out of it because I had to collaborate with others who only used Word. My typing speeds went down a lot in the 7 years since I stopped using vim. If your tool works for me in Word, I may be able to get back in to using vim … I look forward to trying it.

  51. J Says:

    Hi Tom, I hope you enjoy ViEmu for Word. I use it for all email in Outlook, and for all documents I write, and I find it much more comfortable. When you enter insert mode, it’s mostly like the standard editing model, and then you can press Esc and gain all the power of vi!

  52. Vincent DiCarlo Says:

    Great intro, and great tips. I’ve been using Vim for only a few weeks, and it has already become indispensable. I sent a link to your article to my classmates in a beginning class in C++.

  53. J Says:

    Thanks Vincent, I’m glad you liked it. I think you will find it more and more useful and indispensable in the future.

  54. Ovidiu C. Says:

    I don’t know how ‘orthodox’ it is, but I always use ^[ instead of Esc. Esc is just too damn far away.

  55. J Says:

    Ovidiu: quite a few people use ^[. I’ve even had some requests to make ^[ work like Esc in Dvorak keyboards from ViEmu customers!

    I sometimes do, but I usually just hit Esc.

  56. mits Says:

    well, nice article!
    it convinced me to at least give vi a try…
    well, i think i’m gonna search for a similar pro-emacs article first :P
    but seriously, i got a laptop a couple months ago, and text/code editing, among other things, is really a pain, especially when i’m not on a desk…vi’s way seems right…time will tell…
    gotta learn touch typing too… :S (long overdue)
    cheers!
    :wq

  57. J Says:

    Hey mits, I do suggest that you give touch typing some quality learning time, you’ll be happy you did. And after that, vi/vim is the way to go!!

    Best regards and happy new year!

  58. Ali Says:

    May I please briefly pimp PIDA (http://pida.co.uk/) It embeds Vim in a modern-looking IDE so you get the best editor, but in the housing of a much nicer UI. A bit like ViEmu thing I see advertised on this blog, but real Vim, and real free.

  59. J Says:

    Hi Ali,

    Pida looks nice for a general IDE built around vim. ViEmu has the advantage of providing it for Visual Studio (and Word, Outlook and SQL Server), which in some cases is a must. I’m the author of ViEmu so of course I’m biased, but I find VS+ViEmu a very useful and productive development environment.

    Regards,

    Jon

  60. commenter Says:

    I remember how I used to find vi (and emacs) a ridiculous abomination at university, to the extent that I never wasted time learning the arcane details of either. After reading this article, I can see how vi would be much better than notepad.exe for writing code, but as far as it being hugely useful in a modern IDE, I’m totally unconvinced.

  61. J Says:

    ‘commenter’, I can’t provide much more info than what the article shows. There are many thousands of users who use vi editing integrated in an IDE, which is obviously good once you’re accustomed to vi/vim editing and you start coding using an IDE. But of course that’s everyone’s call to make. I for one would not want to go back.

    And btw, I also found ‘vi’ weird and not worth it back in college. It took 15 more years until I discovered what there was underlying the awkward surface and get into it, with no way to go back :)

  62. Mike Kramlich Says:

    great article.
    few more things I like about vi:
    1. no visual clutter - just your doc shown
    2. small resource reqs, works fine even on old slow low-mem computers
    3. you can use it over a remote shell to a prod server (to hack on code, config, or even just to read)
    4. IDE’s sometimes make simple things complex or impossible due to poor UI or arch decisions; vi makes a lot of complex things simple and simple things are simple too
    5. 2 & 3 mean I can use the same tool on ALL my machines, old and new, Mac/Lin/Win, local dev or remote prod- which let’s me be more productive by leveraging that skill set everywhere AND staying in The Zone more often

    Background: my first IDE was Turbo Pascal, my last may be Eclipse, with lots others in between.
    Mike Kramlich
    ZodLogic Games

  63. J Says:

    Mike, thanks for your comments. Using it everywhere is a huge plus for me too. I use it in vim, in my own text editor, in VS, Word, Outlook, over SSH sessions to Linux servers… And I plan to keep on using it for many years to come, no matter what IDEs or editors I end up using. There will be vi emulation for anything I do, or for anything major.

    My first IDE was Microsoft’s QuickC. That’s quite a trip down memory lane…

  64. Shalini Says:

    I’m starting to learn Vi now, loved your article and the chart is awesome !!
    I have one question though, how do you copy a word and paste it. All that I can think of is dw, but that deletes the word, so undo and then take the cursor to where i want to paste it and type ‘p’. i know there must be a better way…

  65. J Says:

    Shalini, thanks for the kind comment. The standard way to just copy is ‘yank’ (just ‘copy’ in vi terminology), which is done with the ‘y’ operator. ‘yw’ yanks from there to the next word start, ‘yiw’ yanks the whole word where the cursor is, etc…

  66. Shalini Says:

    Thanks for the prompt reply. It works great !!
    I have another basic question. Is there a way to add a blank line without getting into insert mode ? I can think of o/O which adds a new line.. Thanks again

    Shalini

  67. J Says:

    Shalini, you’re welcome. Indeed, there is no easy way to that with a comment. I just use ‘o‘ myself, but you can map it to some key if you want. In vim, you can use multiple-key chord mappings:

    :nnoremap _o o
    :nnoremap _O O

    In ViEmu, multiple key mappings aren’t supported yet, so you have to use some other mapping:

    :nnoremap o
    :nnoremap O

    Of course you can map it to whatever you want.

  68. Keith Fullerton Says:

    After spending 35 years in the programming business, I have found that the one universal editor is vi. It is even more important now that Unix and Unix like operating systems are going to be with us forever.
    I have also found that the serious programmer can use it on almost any system and it even works even over high latency satellite links.
    While I use other graphical editors whenever possible, I would be lost without vi.

  69. J Says:

    Keith, I totally agree with you. I just wish I had started using vi 15 years ago, instead of 3 years ago.

  70. Rui Ferreira Says:

    Vimtutor is a great way to get started. Just my two cents…

  71. J Says:

    Thanks for mentioning it Rui, indeed, vimtutor is a good way to get started (I used it myself back in the time).

  72. chris Says:

    I hated VI, always. I first tried it in the 80s, then again in the 90s, before thanking the dear Lord for much better and updated alternatives. Even back then, emacs and micro emacs were totally more intuitive and made a lot more sense.

    I don’t take away anything from those who used VI to the max to do their work. Good for them. But for people who just wanted to write code, and not bother to sit their and master dozens of commands, it sucked. Just my 2 cents.

  73. J Says:

    Chris, I concede it’s not for everyone.

    But I still reiterate that it’s a one time investment, and then it pays off very, very nicely for many years!

  74. functional bytes blog Says:

    Vim Tutorials II…

    Postings zu Vim Tutorials und Cheat Sheets hatte ich ja schon öfter. Jetzt habe ich noch zwei Tutorials gefunden:

    Vim Introduction and Tutorial
    Why, oh, WHY do those #?@! nutheads use vi?

    ……

  75. Cyrus Says:

    Why do they use vi? Because they fucking want to. Because it’s their choice. Nobody is holding a gun to your head asking you to use it… try minding your own business you !@#$ing moron

  76. Silence Says:

    It’s only lazy f-ckwits that complain about vi, sure you gotta use your brain at first to learn the commands; but then it ’s power comes into play. it’s gvim I can’t stand ;-)

  77. Tony Says:

    When I started at university, the first years could not understand why anybody would want to use vi. Everybody tried to use more traditional editors like xedit and the like. By the start of second semester, everybody had switched over to vi for it’s ease of use and it’s speed. Once you have used it, you wouldn’t go back.

  78. J Says:

    Silence: gvim is fine inside a graphical environment, at least under Windows where I use it. Console-vim is probably great in a Unix-centric environment, I guess.

    Tony: what I do find is that hardly anyone goes back after investing the time to learn. Of course there will be some self-selection and those who learn are not a random sample, but in any case I think that proves that there’s light at the end of the tunnel.

    Cyrus, you exhibit such a high degree of smarts with that comment… pitiful. Personal-advice-you-need-even-if-you-didn’t-ask-for-it: do read an article before assuming the content, especially if you’re going to criticize it. Your life will be much better overall.

  79. Gary Says:

    It’s Friday night. I just got home from a night out and and am finishing this article because it got me THAT excited about text editing.

  80. nik Says:

    Thank you.

    I idiot created a macro for example #1.

    But here is a hint for example #2: After yanking the text and pressing O and the “bool ” you can press CTRL-A to insert the last inserted text - that is name of the var. Why tipping something you typed before?

  81. J Says:

    Nik, you’re very welcome. And thanks for the i_Ctrl-A tip, I wasn’t aware of that at all!

  82. Rich Healey Says:

    I’d mention vimperator while you’re here.

    Without it the 80+ tabs that i generally have open in firefox would be unmanagable (in fairness, vimperator + tab kit).

    Still, EVERYTHING is being ported to vimlike.

  83. J Says:

    Rich, I’ve seen vimperator and know a few people who swear by it. Myself, I prefer using regular keys and a mouse or touchpad for browsing, I’m fine with that and I prefer to have my hands free while on the web. I should definitely add a mention in the article, though.

    You’re right that everything gets vi/vim keybindings. Learning vi is a long term investment! I wouldn’t have believed it just a few years before.

    Thanks!

  84. curson Says:

    One of the best article on vi/vim I’ve ever read.
    Absolutely amazing, thank you for this!

  85. J Says:

    Thanks Curson! I’m glad it proved enjoyable.

  86. Eric Says:

    Hi,

    I too have gone from pain to light when I first learnt vi 6 years ago. There was no choice as it is the only editor you could be sure was available on the hundreds of UNIX servers (of different flavors) that we were managing.
    But once learnt, you’re right, one wouldn’t go back !

    An important thing worth mentioning IMO (I’ve not read all comments so forgive me if it’s already been mentioned) is that because you use editing mode occasionnally in vi/vim, you’re focused on the lines you’re modifying.
    And when editing is over and you’re back in command mode, you feel safe, knowing that you can scroll all the way upward or downward your five-hundred-lines-piece-of-code without any risk of modifying accidentally some lines and not knowing it !

    Anyway, thanks for the article ;-)

  87. J Says:

    Eirc, thanks for the suggestion! It’s funny, I also feel like that now, exactly opposite to the first few weeks of using vi/vim, which make you feel scared of damaging things *when in normal mode*! That was four or fives year ago now, amazing & scary how fast time goes by!

    Thanks for the comment!

    — Jon

  88. Gavin Says:

    @Jon: I’d give vimperator another look if you haven’t already. The progress it is making is awesome, specifically the [[ and ]] commands. CTRL-x, CTRL-a and ‘gi’ in particular are great too.

    Just saying, it’s become more than just a few fancy keybindings.

    Cheers.

  89. J Says:

    Gavin, thanks for pointing that out. I have a friend that uses vimperator all day, and I sometimes have a look at his installation. I’ll mention those commands to him. And I’ll have another look again when I can find the time, so many people recommending it must mean something.

    - Jon

  90. G Says:

    Brilliant article,

    Good work on clarifying some of the fundamental philosophies behind / strengths of vim.

    I learned alot here

  91. J Says:

    G, thanks for the kind words.

  92. Ryan Hunt Says:

    If you use a Mac there is a great version of Vim available that fully integrates with the Cocoa framework. i.e. It has fully functional transparent backgrounds, and can go full screen too. this makes watching movies behind the text possible. A great way to multi task your coding and entertainment.

    It can also add an “Edit in MacVim” menu item in the edit menu on all text editing programs on the system. Very useful.

    Check it out at:

    http://code.google.com/p/macvim/

  93. J Says:

    Ryan, thanks for pointing that out to me. I was actually aware of MacVim from looking at my http logs, as that project’s front page (the one you mention) links to my “Why use vim?” article :)

    I only use Windows PCs and Linux servers remotely, but I do plan to start using a Mac at some point (although not before I can fully justify it as a business investment and not as a toy!). I’m sure I will look into MacVim then.

  94. jes5199 Says:

    I’ve been using vim for ten years, but I’m about ready to give up on it. It just can’t correctly indent any language that’s more complicated than C, and that includes XML and Ruby.
    And the above comment about code refactoring tools: this is something that the open source world is really missing out on. I’ve never used one, but my Java and .NET buddies are getting to the point where they don’t want to code in a language that doesn’t have a refactoring tool suite available.

  95. Worm Says:

    Great article. I just have one mostly insignificant comment. I find that most people seem unaware that not all keyboards have a US layout. You wrote:

    ‘#’ does the same backwards, at symmetrical positions so its easier to remember

    But, of course, on my Latin American keyboard ‘*’ and ‘#’ are not at symmetrical positions, and they don’t even both require shifting with the same modifier key.

  96. Svish Says:

    Yeah, non US layout is one of my problems with vim as well. especially the {[]} keys, which requires me to press Alt Gr+7, 8, 9 and 0. And that sometimes don’t work at all, for some reason I don’t know.

    Also, I see you have syntax highlighting. Is that possible to get in regular vim in a terminal?

  97. J Says:

    jes, most of the time I use Visual Studio with ViEmu for my development, so I can understand both of your points well. vim is great for some things, but indeed it can be improved upon on many fronts of text editing. Still, what I like to see is a great, modern text editor with vi/vim editing, which has the best of both worlds (many ViEmu customers use VS + ViEmu + Resharper or Visual Assist X, so many people actually agree with you).

    Worm, you are right, I use a Spanish layout keyboard (I’m from the Basque Country in the north of Spain), where the problem you mention happens. I switched to using a US layout several years ago, in order to use what is more universal and most of my customers use — and some things make more sense, like the placement of * and # for vim, and even the punctuation signs to the right of the “m” key, which give meaningfulness to the design of xml/html and many vi commands (/ and ? for forwards and backwards search).

    Svish, you can get syntax highlighting working in vim via a terminal if things are configured properly. I’ve done so using putty to access a unix shell via SSH. I’m sorry I’m not familiar with the details (I’m not a Unix guy!), but I’m sure you can Google around for that.

  98. Kaz Says:

    One of your very first examples invokes nonstandard vi usage. Commands like A cannot backspace over material. Standard vi does not allow that. So you cannot use a single A command to kill the trailing semicolon and add a body. This is a Vim-specific behavior which doesn’t work if you :set compatible. I think there is a more specific variable to turn this on and off, too.

    The vi way to do this, interactively, would be to position the cursor on the last character of each line (by typing $). Then use an s command to nuke the character under the cursor and insert the curly braces. To repeat that on each line, you have to position the cursor with $ before hitting period. Or you can memorize a regex search for the semicolon and repeat it with n. Then you’re typing n.n.n.n.n.n.n.n.n to add the curlies. Each n goes to a semicolon, and each . repeats the s command to replace it with a newline and curlies.

    The vi standard behavior (no backspace over existing text) is yet another vi advantage. When you’re editing over a lagging remote login session, and type too many backspaces, the editor won’t eat characters beyond the beginning point of the insert. Also, bckspacing out of the edit kind of ruins the concept that the command has a target object that it operates on. Bill Joy designed that for a reason. E.g. “cw” is supposed to change a word, right? Well, if you backspace out of that, you’re no longer changing just that word, but nuking what came before it.

    Anyway, if you incorporate lots of nonportable hacks into your core text munging technique, you will be stumped if you have to use a different implementation of vi from what you are used to.

  99. J Says:

    Kaz, thank you for your comment. As you can see, I am more familiar with vim than with the original vi. For many people nowadays, ‘vim’ is what they’re talking about when they say ‘vi’, even if it’s incorrect.

    Your explanations are very clarifying, and I’ll just wager that I think the article keeps its value even if there is a non-standard feature used in one of the points. I’ll try to be more precise in the future, though.

  100. Robert McGee Says:

    I’m glad you all love vi. You should get your free copy of Visual Studio 2008 Express Edition and really learn how to use it so that when you declare everything else to be lousy and inferior, you are speaking from a position of knowlege.

  101. Jon Says:

    Robert, the two are not mutually exclusive, as you can see in my product: http://www.viemu.com . I use vi/vim editing all day inside Visual Studio, and it gets me the best productivity. I have been a VS user for many, many more years than a vi/vim user. I’m not the only one who thinks this way, either, you can check this on this page: http://www.viemu.com/viemu-testimonials.html .

    ViEmu won’t work with the VS Express though, as MS doesn’t allow loading external add-ins on Express Editions. You need one of the commercial editions to try it out. But I’d definitely recommend it.

  102. Robert McGee Says:

    I meant not using vi at all, rather than using vi within VS. I’ve used VS since version 1.2 (about 1993) and always used their built-in editor. With lots of features found in context menus or mouse fly-overs, I’ve never needed any of the vi tricks you describe, or UNIX command line tricks either - VS does all these things, and much more. I tend to use Class View rather than ‘Solution View’ (which could be called ‘file view’). VS 2008 and .NET include some incredible new things, like automatically creating blocks of text for comments, various code constructs etc. The basic idea is to move beyond editing code one character or line at a time. I like the way it works and the direction it is going. I look forward to every new release of VS, wondering what goodies I’ll get next!

  103. Jon Says:

    Robert, I’m familiar with MS languages and IDEs since at least as far back as you. I was using Visual C++ 1.0, which was 16-bit only, and even before that, Microsoft C (I think the last version was 6) and Quick C, which was a great text-mode IDE a-la Turbo Pascal. It’s there where I learnt my earliest C. This must have been ‘90 or ‘91.

    Obviously, I’m not against it, I actually think IDEs are a great win for most daily work. But for raw text editing, the vi/vim model is unmatched, once you’ve learnt it.

    That’s why I think VS + ViEmu is the killer environment for C/C++/C# development (possibly with some other 3rd party refactoring tool).

    I think the future lies in more dynamic languages, and the productivity of, for example, Python (in another very different sense) is nearly impossible to match, but this is another discussion).

  104. WordPress Hacker Says:

    You know your vi gang sign looks suspiciously similar to the shocker.

  105. Jon Says:

    wphacker, indeed, I was made aware of this some time after posting the article. I wrote a detailed recount of this:

    http://blog.ngedit.com/2007/11/19/the-vi-gang-sign/

  106. Seth Says:

    Thanks for a well-written backgrounder on “why vim”; keeping a bookmark as I grow tired of trying to explain this myself :)

  107. Jon Says:

    Thanks Seth, I do think the graphical cheat sheet and this write up can be generally useful for us vi(m)ers to communicate to the rest of the human kind.

    - Jon

  108. kai Says:

    Really good examples, thanks a lot for the tip, VI is amazing.

  109. Jon Says:

    kai, you are very welcome. Glad you liked it. And indeed, vi is amazing!!

  110. Pablo Says:

    Excellent lecture man!
    Really good arguments to demonstrate why vi is at the same so good and so different.

  111. Jon Says:

    Pablo, thanks! I’m glad you enjoyed it. I hope I’ve helped in the battle to explain vi to non-vi(m)ers, or rather defend it from them!

  112. Tim Says:

    Great article, and almost matched the Google search I used to find it! 8) One thing that bothered me a little frankly was the last sentiment about “staying in your IDE and using a lousy editor” which kind of showed me a bias.

    Would you suggest the editor in the JetBrains tools to be “lousy?”.

  113. Jon Says:

    Tim, thanks for the kind comment. I didn’t really mean that all IDE editors are lousy, only that most are :)

    To my defense, it was a low-key ending to the article, and some vi(m)ers complained that it was too tolerant!

  114. hansmuff Says:

    Absolutely great blog entry!
    I have used VI and use it on a semi-frequent basis. I have tried to get efficient in it and failed because most VI references just explain just how powerful the commands are.
    You delivered a very nice explanation of the underlying model.
    Good job, and Thank You.

  115. Jon Says:

    Hansmuff, you are very welcome. I really felt that an explanation like this was needed, and I’m happy it turned out well.

  116. modern_unixman Says:

    For those of you non-VI readers who read this and said “ok when is he going to get to the good stuff”, he’s not. Yes, you can do everything he mentions in any good text editor, often much more intuitively.

    So if you find yourself saying, sarcastically, “oh wow, you can select from one bracket to the next with a few keystrokes. oh wow, you can do some keystrokes, then repeat them again with a keystroke. oh wow, you can indent multiple lines of code”, you are not crazy.

    The main advantage of vi is that it is everywhere. When skynet takes over and you have to hack into the matrix to cause a snowcrash, you’ll be using vi on wintermute.

    But if you’re using a modern editor with code completion, syntax highlighting, svn/git blame/annotate integration, side-margin error/warning icons with hover, control-click-on-symbol-to-navigate-to-its-definition functionality, integrated debugger with hover, etc., etc., and you like it, then stick with it, and when someone tells you that you don’t “get” VI, just tell them, “yes I do, and it is the only editor I ever use, and everything else is horrible”, smile, and keep walking.

  117. admin Says:

    Well, Well, everything is true, Vim is the best..

  118. Jon Says:

    Modern_unixman, as I hope ViEmu shows, we vi(m)ers understand the value of code completion, synhl, debugging, etc… we only like to have vi/vim commands for the low-level editing, perfectly integrated with the rest. I often use code completion to type something, and then use vi’s ‘.’ dot command to repeat it. What could be sweeter?

    admin@it-hacked: if not the best, vim is at least one of the very best!

  119. Saswat Says:

    This is one of the best explanation of vim features I have seen.
    thanks !

  120. Jon Says:

    Saswat, thanks!

  121. Dr. P. Brain Says:

    Why use vi(1)? Because if you use emacs(1), exec(2) will return 1 with errno set to EEDITORTOOBIG.

  122. frank Says:

    because we can

  123. frank Says:

    code completion… mmmm maybe instead of relying on code completion… better understand what you are doing… code with intent..

  124. Jon Says:

    Frank, code completion can be used by both those who don’t know what they are doing, and also by those who know what they are doing but don’t have 100% perfect memory. I wouldn’t be so quick to judge.

  125. max Says:

    You’re still a bunch of propeller head geeks freaks. lol

  126. pallgone Says:

    Wow, some comments, eh?
    Whenever I “have” to use vi/m nowadays (I was using it for some months exclusively) I hate it. Mode changing is a pain. You waste so much time for that alone. Not mention that ESC is far away (yes, I know you can switch keys).
    So I’m always happy to get back to emacs…

  127. Jon Says:

    Pallgone, tastes are still tastes, there’s always the good, and the better :)

  128. Pran Says:

    Great article! I loved the justifications and reasonings behind the ideas/misconceptions behind vim.

  129. Ville Says:

    Thanks for this article! It certainly shed some light on “why do those nutheads use vi?” — a thought that has many times crossed my mind when beginning configuration of a newly installed system (when I haven’t yet installed a more user-friendly editor). The first segment (”modal editing”) made use of vi immediately more bearable, and no longer do I think: “How do I EXIT this DAMNED thing?!?” when I enter vipw with vi as the default editor! :D

    I still think joe is the best general-purpose editor, but at least vi no longer seems totally meritless.

  130. Jon Says:

    Pran, thanks for the compliment.

    Ville, I’m glad you saw a bit more of vi and you can see some of its value. I assure you that if you invest extra time, you would see where it becomes something one can’t live without!

  131. Satish Atakare Says:

    Great Article on vi/vim.

  132. Sebastian Says:

    I was quite amused when I read your Example #1: the wonderful dot command. Because you just discribe a different way of doing copy and paste.
    Anyway, I still admit that a developer who’s really good at using vi might be a bit more productive than one who is very good in using IDEA or Eclipse. But besides that I think the average developers is better off with a normal modern IDE.

  133. Song Says:

    thanks man. You explained what I wanted to say, but in a better way, in misconception #5. Vim is like a pen to me — I am not aware of its existence most of the time.

  134. Rocman Says:

    I’m new to programming so this may seem like a stupid comment but what the #?@! is the point to using vim? I’m looking for a Perl IDE, I have VS, which is awesome bty, and was told that vim was it! as far as a Perl IDE. Thus far it doesn’t do anything but edit text. What point am i missing?

  135. Jon Says:

    Hey Rocman, actually, I can’t express it any better than I did at the article above:

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

  136. regac Says:

    Mind = blown. Accidentally stumbled upon this, and although I’ve tried Vim (and didn’t like it) I just started to grasp its full potential.

    I’ll probably have to get around to learning it: too bad the learning curve is **steep**.

  137. Jon Says:

    Regac, let me encourage you to climb the steep curve. It’ll payoff later on!

  138. 249 Says:

    Last year I decided (after getting sick of having to crack software to use it on windows) that I would go 100% Linux (Fedora to exact) and leave the worries of windows behind. I looked at and tried almost every editor that was/is available.. VI was/is the only editor for me. It was weird at first but, a few days of using it and I am hooked.

  139. mandeep Says:

    the only drawback of learning vim that i faced was that i got so used to it’s commands i was missing them everywhere, be it browser or excel document or word file ;-)

  140. Jim Says:

    It’s hard to go back to an IDE, I agree. The trick to using VIM well is to find a tutorial that shows only 10-30 basic tricks. Ignore those that try to show the full power of VIM in 1 blog post, you’ll just feel overwhelmed. I tried to use an IDE a few weeks ago, but with all the “helpful” popus and pauses, it would just ruin my concentration and productivity, never letting me get in the “zone” where I’m extremely productive, for more than 2 minutes. VIM just gets out of the way, fades into the background, and does not ruin those important times of high productivity.

  141. Steve Lehar Says:

    Great article! I’m an old emacs guy (57 years old!) and just re-converting back to vi just to keep my mind fresh. One thing that would be VERY useful would be a plain-text file containing example code and explanatory text, so as you read the explanation you practice it immediately right on that text file, instead of having to pop over to another window to try what you’ve just learned. Example:

    Try navigating through this text using w and b commands. Now put your cursor on () to the matching parenthesis. Now move your cursor {into these curly braces} and type da}. See what happens? Now type u to undo, and try dab and the same thing happens. But dab will also work within [square brackets] or {curly braces}, where you could also use da] and da} respectively.

  142. Jon Says:

    Steve, thanks for the comment. I think there is something like what you mention: the ‘vimtutor’. In Unix, you just need to run ‘vimtutor’. In Windows, you can look for vimtutor.bat in vim’s installation directory. Start it, and you’ll see that it’s self-explaining and quite close to what you describe!

  143. Jason Kenney Says:

    I use vi on osx with terminal full screen is an excellent distraction free environment.

Leave a Reply