Why are vi[m] efficient code editors?
I am always one interested in learning. And that is why I decided to launch this thread. To be clear, I am not interested in engaging in "mine is better than yours" discussions that invariably lead to flame wars.
The intent is to hear from vi[m] expert users on the reasons those of us who, like me, only touch vi[m] when absolutely forced to, or others who chose to avoid vi[m] or barely know anything about these editors should seriously consider what vi[m] have to offer.
I propose that posts should take the form of reproducible recipes. Give us, vi[m] neophytes, steps to follow in order to understand how one might do a specific task more efficiently using vi[m]. Please don't engage in comparing it to anything else. If we keep it to vi[m] recipes then this thread stands a chance of becoming an educational resource for those of us not familiar with these methods.
This also means that making claims about vi[m] efficiency supported by saying something akin to "every programmer who uses vi[m] thinks so" are not acceptable. Only recipes.
Also, in the interest of fairness, the recipes should work with unmodified vi[m]. Requiring the loading of plug-ins of various kinds muddles things as the same could be true of other editors.
In addition to this, let's not talk about things like memory foot print or binary size. With today's multi-gigahertz-multi-gigabyte computers this really is immaterial.
A recipe could start by suggesting to clone a certain github repository, then opening a specific file with vi[m] and then offering-up a series of commands that show how to derive efficiency gains from vi[m].
On my end, I have access to OSX, Linux, Irix, Solaris and emulators on Windows machines. Other readers might only have one platform available. Please indicate if your recipe, for some reason, requires a specific platform.
Finally, please don't comment on my introductory (first) paragraph. Only recipes and discussions that ask questions or offer clarifications on the recipe in question.
Thanks.
I'm puzzled at how you can ask about 'gains' and at the same time, discourage comparing vim to anything else. Isn't your question about relative advantage?
If you disqualify things like startup time, portability, and plugins you are now talking about a meaningless comparison. Those are real features vim has and you are just trying to exclude them in an effort to tilt toward your predetermined conclusion that vim is bad.
In the end my productivity at any work station is not defined by which program I use, but how well I know the code. I try to not let my environment affect my workflow as much. If I sit down at any computer with some way of SSH, or a terminal emulator then I will be able to code my heart out.
One last thing I notice with vim, everything seems to be a keystroke away. Searching and moving the the next line, adding to the end of the current line, indenting the line, moving to the beginning of the line. It's so quick. Certainly every other editor out there has realized this and has the same features, but they are gummed up by the fact that they are always in insert mode. For me it is faster because I don't use left shift or control. Some people prefer emacs style bindings for everything they do. They don't mind throwing the left pinky down and hitting shift or ctrl. I find it so unusual so I find vim bindings much easier to become accustomed too.
Does that provide any help?
Not a recipe, but yes.
Can you explain this comment a bit further: "they are gummed up by the fact that they are always in insert mode"
How is being in insert mode problematic? A scenario or two might be useful.
I use vim with git all the time and can't say I enjoy having to go in and out of insert mode every time I touch it.
Since a large part of editing a text file is manipulating the text that is already there, most of what makes vim powerful hangs out in the other modes. In "normal" mode, you can type out two or three keys and quickly communicate not only where you want the cursor to begin editing, but also how much text you want to replace. There are a endless number of these short little sentences you can communicate to vim quickly about where and what you intend to edit.
This kind of complexity can be intimidating to a new vim user, especially if you go looking for a vim cheatsheet and find that keyboard layout that shows what each key does in each mode. YOU DON'T NEED TO KNOW THAT. At least, not yet. Just install the vimtutor package, repeat it every once in a while, and internalize the basics. Learn the things that are useful to you. Most vim questions are wildly googlable. Type in ":help", and read the description of how the command and navigation works. Then use it whenever you can't remember how every other command works.
There is no recipe or anything to get really good at Vim. It's up to the person using it to get a firm handle on what is going on. Some times you just have to be curious and notice that there could be a performance tweak here and then research how to do it. Also, don't be afraid to make your own macros to take care of work for you. I have plenty of self defined macros. Taking all the work from someone else doesn't make it entirely yours. Tweaking and picking from tons of other vimrc's and the like can be interesting.
As a tid bit, make your own dotfiles repository on github. I have about 15-20 systems where my dotfiles directory is symlinked and as long as I have internet I can transfer around my perfect environment.
The mental image I am developing now is that vim can be said to be efficient in a narrow sense. Perhaps that narrow definition is constrained to the file level. It's like a musical instrument to manipulate files. Once you know it well, it feels just like that. I am not saying that this is the only definition, it's just what I am coming-up with now.
Once we deviate from whatever the narrow definition of where vim is more efficient the claims start to fall apart. This doesn't happen because of vim but rather because it is the very nature of creating software: Things take time and saving keystrokes at the file-editing level isn't going to bring a project to completion six months earlier and with less bugs.
I wear at least two hats: developer and businessman. I am forced to look at things from both angles, because, well, I have to pay for the consequences of my own decisions. For example, if I succumb to my natural inclination to keep adding features it means that I might have ten programmers busy for weeks chasing an ever-moving project completion milestone. So, as a business person, I do my best to control these urges and look at things through a different equation. Eventually you have to call it "done" and move on.
Over the years I have never seen any code entry tool that truly makes a serious dent in software project timelines. Software projects are notorious for being late and over-budget. And this has absolutely nothing to do with the tools we use. Zero. A better editor or IDE will not make a dent on overall project timeline. Anyone who can figure out a way to solve that problem can become an "instant" billionaire.
The Agile crowd makes that kind of claim, some language zealots also do.
The "saving keystrokes" argument is important for programmers because our work is very repetitive and we are lazy. It has nothing to do with the productivity of your team or the release date. Nothing. Because programmers don't care about all that. Chosing Vim over another editor is a matter of personal choice.
If you don't like Vim don't use it. Noone cares.
if you are interested, even remotely, try it in your free time.
But by all means don't project the effects of your delusions on random strangers: nobody is insisting that you use Vim instead of X. All the "Vim is awesome" comments or blog posts you have read are not attempts to bring you to our temple. They are just manifestations of our personal and often unreasonable "love" for Vim. No more, no less.
When you aren't in insert mode, it's easy to navigate to specific lines (g), scan quickly through the document (^D, ^B), scan through lines (b,e), change/delete stuff (c,d,C,D,s,etc. Quick commands like ci" will Change Inside Quotes, so for example you can edit strings very quickly.), and search (/, , #, n, N).
As well, like tlunter said, vim is very portable. If you have to hop on someone else's computer to change some of their local code, there almost certainly* will be an editor that you can use quickly and efficiently. It also loads very quickly.
"Give us, vi[m] neophytes, steps to follow in order to understand how one might do a specific task more efficiently "
I believe this is the strawman that was being alluded to in the previous thread. Nobody is going around saying "Hey, if you don't use vim, you are producing less than I am!" Okay maybe some people do say that, but that's really not the reason people love vim.
The real reason (in my opinion, of course) has to do with flow. It's hard to explain, which is why these discussions tend to digress. But when you're in flow, or the zone, you don't want things like your text editor to get in your way. You want it to be a harmonious extension of your intentions to the machine. When you connect with vim, that is what you get. Other people might get that connection with emacs, or some other editor. But for the most part, you just don't get it with editors that don't allow a rich communication vocabulary between you and the machine.
Does flow matter on the scale of business deliverables within a project budget? Not really. It matters to the enjoyability of the creation experience that the programmers are involved in. They could probably still produce the work without that additional enjoyability, but less enjoyable work can sometimes lead to lower quality. And perhaps more importantly, it always leads to less joy.
For the past several years I've been using a keyboard that doesn't require me to move my hand away from the home row in order to manipulate the mouse cursor. There's a similarity there in that it reduces flow interruption. I've recently started learning vim because I see this same potential in it.
As for "recipes", there is a post here taken from the previous thread: http://www.viemu.com/a-why-vi-vim.html
I understand flow very well of course. I can't say that I've ever used an editor that prevented me to enter that state. I a not countering your statement, just providing my own experience.
Aside from programming I play the piano and classical guitar. When I play music I am in flow. That didn't happen until I had reasonable command of the instruments. With vi (or any other tool) the same is required. I wonder how much time it would take to go from vi neophyte to playing it like a piano? That initial phase is painful if you have to get work done.
I also understand the value of playing a good instrument and using good tools. And, while this value may not provide any hard quantifiable benefits to the project timeline it does provide benefits for the practitioner. The project might still be six months late, but there will be more daily enjoyment, if you will, for the practitioner to remain on focus. That could have value. Whether or not there is a difference between someone who has never touched vi and a vi expert remains to be determined. The vast majority of programmers don't use vi.
After reading your post and others on this thread my immediate reaction is that vi advocates might want to consider not characterizing vi as "more efficient" but rather highlight what it might do for a programmer. I can't come up with the words right now, but "more efficient", in my book, calls for having quantifiable data at the project level (not the file level).
We all know that saving a few keystrokes here and there isn't going to bring a project to conclusion any sooner. We had a project where we spent six months tracking down a bug that was due to a rounding error someone made in a calculation of lookup-table data used in a polyphase FIR filter module. It was one of those things that was right in front of you but nobody could see it. The project was late by an additional six months (it was already late) because of that bug. That's the kind of thing I think about when I say that saving a few keystrokes on the editor doesn't matter in the context of a project.
I'll read the article you pointed out and see what else I can learn.
Thanks for your input and valuable insight.
Being more efficient at manipulating text means less energy spent, which makes for happier programmers. So the more efficient text-editing is preferred by some, not because it leads to better software, but because it leads to better quality of life. And I stand by the statement that vi[m] is more efficient at manipulating text, while not disagreeing with you that it makes no difference at the project level.
I can absolutely agree with you on that. Learning vi[m] in order to get to that level seems to be the hit lots of people are not willing to (or simply can't) take. In the context of a busy shop it makes almost no sense to bring productivity down to almost nothing while everyone has to slow down to learn a new tool (any tool, not just vi[m]). The only time one can justify this sort of thing is when there are real and measurable business or code quality benefits to the interruption. An example of that is sending everyone out to a one week course on a new technology. When they come back they absolutely rock. I've sent people out to take courses costing the company tens of thousands of dollars on more than one occasion. In every case it pays off within days.
I can't say that about vi[m] yet. Not wanting to voice opinion from a context of ignorance I will spend time over the weekend to force myself to dive into vim and see what I can learn. Happy programmers, hell, happy people, are always more fun to work with and be around. If vi[m] can bring that to the table I have no problem promoting its learning and usage at our shop (when we can afford to take the initial productivity hit while everyone learns).
http://www.microsoft.com/en-us/download/details.aspx?id=2375...
older, but better explanation: http://technet.microsoft.com/en-us/library/cc779522(v=ws.10)...
And a blurb on how to go about enabling some of the functionality:
Fortunately we are running Vista Ultimate 64 bit, which makes playing with this subsystem possible.The thing that makes me rage when I'm forced to use an editor other than vim is "Ctrl-RightArrow / Ctrl-LeftArrow".
Will it stop on spaces? Will it stop on commas? Will it stop on parenthesis? If I hit Ctrl-Right->Right->Right then Ctrl-Left->Left->Left do I end up back where I started?
I cannot fathom how people blindly accept that their editing movement operations are inconsistent. In case it's not clear, by default in windows most text editor areas do not "properly" return you to where you started with a bunch of Ctrl-Right/Ctrl-Left pairs (although I can't tell you at the moment what characters actually trigger this issue).
Finally, by being a "modal" editor... when you want to type letters and stuff, getting into insert mode is an extremely small price to pay in comparison to having 26 function keys under your fingertips at all times.
"""Vi has the advantage that most ordinary keys are connected to some kind of command for positioning, altering text, searching and so forth, either singly or in key combinations. Many commands can be touch typed without the use of ⇧ Shift,Ctrl or Alt. Other types of editors generally require the user to move their hands from the home row when touch typing:"""
...the idea being that when you're actively typing, vim is just as crappy of a text editor as anything else (notepad, bbedit, etc.) but when you're not typing you've got at least 26 letters which all do something, then 26 more because you can type shift.
q == record macro, w == move by word, e == end of word, r == replace character, etc, etc, etc. (don't make me type them all out, we'll be here a while! ;-)
That can be a problem if you have to jump from platform to platform or work with IDE's that implement things in vastly different ways.
I jump between Windows and Mac all the time and for the longest time the Mac keyboard was infuriating. My solution was to re-map it to match, as much as possible, what I was used to. That may very well be the case with vim advocates. To be clear, this isn't about one or the other approach being better by any measure of the work. It's simply that one tends to prefer that which is familiar. That's just the way every person is wired. I've seen this across disciplines that have nothing whatsoever to do with programming. Resistance to change is a strong force. We tend to want to stay with what we know and reject change at a visceral level. And that's OK.
Your point are probably valid. I'll take the time to explore over the weekend. Thanks for taking the time to share your insights.
i decided to write here how i use vim in no particular preference:
vim's J keystroke (that joins the line in succession with the one you're on) is the most frequent reason i use vim on whatever platform.
next, s/this/that/g search and replace is quick for regex based string replacements
next, vim -d file1 file2 visual difference is pretty great in console or in the gui mode (gvim)
next, on a unix system if you're dealing with C sources for a big project, ctags allows vim to provide the feature where you press CTRL-] and it takes you to the definition of that symbol. This is similar to other editor's right click and 'go to definition' context menu.
i'm not trying to sell vim to you or readers of HN; i'm simply advising to read :help in vim to the best of your abilities the same way you would read about other editor's help pages/cheat sheets and the sort to determine value for yourself. i do agree that examples sometimes enable you to associate with one or the other editor; i dislike using vim for editing all sorts of files. i use vim for things i can quickly get done in it, using other tools for whatever they're good at, if that makes sense.
Do you have a link to the port?
use whatever you like and works for your workflow.
The important thing that Vim does for me is to reduce to an absolute minimum the amount of keypresses it takes to write the code I want.
Simple example: It's a common practice when people are putting in blocks of comments to put in an eighty-character line of hashes to delineate it - something I'm sure every coder has seen. And it's not hard to just hold down the hash key until it's reached the end of the line. But it's far quicker and more reliable in vim: 80i#<ESC>
Say I'm editing code near the bottom of a screenful of text. I want to see a couple of lines that are just off the top of the screen. In most editors you'd hold down the "up" key until your cursor reached the top of the page, keep going until the lines you wanted were on show, then hold "down" until you got back to where you started.
In vim, Ctrl-Y a couple of times and you're done, without losing your place - your cursor stays in the current position, on the current line.
The regex-capable search + find&replace is invaluable - Earlier today I had to generate >100 tests based on information spread through multiple spreadsheet tabs. This would have been hours of work doing point&click copy-pasting, it was done in a few minutes courtesy of a couple of regexes.
Moving blocks of code around when refactoring is effortless: di} to delete all the code in the current JS function and copy it to the buffer, move to where you want the code to be, 'p' to put it in its new home.
The "snippets" plugin giving TextMate-style functionality is very useful, a big plus for vim's ability to be programmed, which I also use extensively. For example, we often need to look at information stored by our web application in a database. We used to have to either access it via the DB or use the web app itself to display a poorly-formatted static text output. I created a Vim command that retrieves the data, orders it, formats it, syntax hilights it, and makes it far easier to navigate & search.
I've used IDEs, I've used other editors, and Vim is simply better than all of them. IDEs in particular spend more time getting in the way than they do being useful. Vim is the closest thing there is to being able to take the code I have in my head and dump it straight into a computer.
And given the number of studies that show that a single interruption to a coder can result in a half-hour delay whilst he rebuilds his mental stack, that makes Vim a tool that can save you hours of productive time every single week.
I can't really comment on the rest of your excellent post until I try some of these things out. I intend to spend some time with vim this weekend, try out some of the ideas presented in this thread and see what I can learn.
I can comment on this: "And given the number of studies that show that a single interruption to a coder can result in a half-hour delay whilst he rebuilds his mental stack, that makes Vim a tool that can save you hours of productive time every single week."
I've been programming since I was ten years old. I have well over twenty years of experience in the field, across multiple platforms, tools and languages. I started out with machine language. Not assembler, actually typing in hex instruction codes into a keypad. Back then, I used that approach a number of times to bootstrap a Forth system onto a newly built computer board (something like a 6502 board). One of the first things you do after that is write an editor (in Forth) so you can start moving faster.
I have to say that in all of this time I have never had an editor get in the way of the programming task to such an extent that it can be considered an interruption. Interruptions that disrupt the mental stack you refer to are very real and they suck, but, in my experience, the text editor is never the issue.
Again, thanks for your valuable input. I'll spend some time absorbing it over the weekend. I need to get a project out first. Damn priorities!
* A nagging desire to drop Mac OS X in favor of Linux and, therefore, the necessity to find an alternative to TextMate. * TextMate's learning curve is very flat and very short. After years of heavy usage, I was bored. * I've seen a couple of "magic" Vim screencasts that left me drooling like an idiot.
Because of the first point, I've spent a significant portion of 2009 trying out all the Linux/cross-platform editors/IDEs I could find: Gedit, Geany, Kate, Scribes, Redcar, Emacs, Vim, Eclipse, Komodo, IntelliJ IDEA… I've tried them all. I wanted completion (even basic), some kind of snippet system, themeability, fast navigation… and all of it was available in one form or the other in most of those editors/IDEs.
Because of the second point, the over all design of the editor, the steepness of its learning curve and all sorts of subjective details (keyboard friendlyness, scriptability, active community…) were also weighted when trying out all those editors/IDEs.
Because of the second and third point, I was very curious about Vim. It was the most "special", advanced users seemed to be able to fly and it was cross-platform. The String Calculator Kata In Python screencast (http://vimeo.com/8569257) by Gary Bernhardt, despite showing an heavily customized Vim, was mesmerizing. It's very subjective, I know, but I felt that Vim was just my kind of "special".
But yeah, it was really "special". All my attempts to use it had been very frustrating and I was about to settle on Eclipse.
Then came the right occasion: I had a totally empty week before me. Nothing to do at work, my kid was at his grandparents'… So I decided to give Vim a serious try.
I decided to start right at the beginning: $ vimtutor, which I did a good twenty times. After each session, I opened an old html or js or txt file and tried to apply my new knowledge. Of course the first day or two were very unproductive and frustrating but I had a lot of time and no obligation of prductivity so kept trying. After a week, I knew all the basic commands but I was definetely not ready. When, finally, I had some real work to do I naturally turned to my trusty old TextMate while I spent a couple of hours every night watching screencasts, reading tutorials, practicing and, above all, doing the biggest rookie mistake: trying to turn Vim into a TextMate clone.
I installed lots and lots of plugins, filled my .vimrc with hundreds of lines I didn't understand copypasted from people I didn't know and tried to map 1 to 1 Vim's and Textmate's keyboard shortcuts. After a few weeks at this rate, my Vim was an horrible and slow mess. It took a lamentably failed attempt to use Vim on a VPS for me to actually accept my failure and decide to go back to square one.
I deleted the content of my .vimrc and of my .vim/ and tried $ vimtutor again. I was a new "student": more open minded, more willing to learn. It was only at that time that I found myself suddenly blown away by the elegance of Vim's design and, yes, the SIMPLICITY of its language. Before that, aJc/ and Co. didn't really make much sense. After that, it took one month or so for me to finally make the switch after "solidifying" my newfound zen.
For me, it was mostly a question of design. And of being in the right state of mind.
So no, I won't prove you why Vim is better than X. That would be pointless because a. I don't care about you or the editor you use and b. I'm perfectly satisfied with the choice I made and I don't feel the need to convince myself through others that I was right.
Use whatever tool you prefer/know/need/can afford.
Instead I will show you a few things I THINK are cool.
I understand that most if not all of it can be achieved in most code editors but, in my opinion, none allows me to do all that in such an elegant and natural manner.Based on your story it is clear that vi is not a weekend project. I am interested in learning so that I can have an opinion that is based on more than the "fuck this" reaction I have had over the last twenty years every time I've touched it on many platforms.
I am also impressed by your process and dedication to exploring the space. One can only respect that approach and the conclusion you reached. I too have used a ton of editors. For some reason I've never had the patience to really get into vi. But now I will. Because I owe it to myself to know what everyone is so impressed with. What happens from there is a different matter.
Also, thanks for not resorting to insults or calling me a troll as others who never seem to contribute anything of value have done.
Thanks again.
BTW, if you have more screencast links feel free to share them. I'd appreciate it and I am sure that others who are reading this and might have had the same level of rejection of vi would too.
There are many screencasts available on the net, paid and free. The best ones happen to be free.
Drew Neil's screencasts at http://vimcasts.org/ are laser-cut, focused and short. Each video is about one or two specific use-case so you don't get overwhelmed by dozens of "cryptic" commands. The production value is amazing (not in the Michael Bay meaning of the word).
Derek Wyatt's Vim Tutorial Videos at http://www.derekwyatt.org/vim/vim-tutorial-videos/ are the opposite: messy, lighthearted, funny, hysterical and packed with gold nuggets. You'll probably need to watch them a few times if you really want to extract practical knowledge.
Peepcode has three Vim-related screencasts but I think they are really bad, specially the "Play-by-Play" one.
Yes. Vim is not a weekend project. There's no way you can reach your previous level of productivity in one weekend or two.
May I suggest you, based on my own experience, to not install any plugin and not copy someone else .vimrc? Play around with $ vimtutor, exercise on random files (not on serious stuff), read the help (:help<Enter>), watch a bunch of screencasts to get the feel of what it's all about.
After the weekend is over you will either be craving for more or be disgusted.
Consider both outcomes as a succes and move on to the next step.