views:

6817

answers:

35

As a programmer I spend a lot of hours at the keyboard and I've been doing it for the last 12 years more or less. If there's something I've never gotten used to during all this time is these annoying and almost unconscious constant micro-interruptions I experience while coding, due to some of the most common code editing tasks. Things like a simple copy & paste from a different line (or even the same line), or moving 1 or 2 lines up or down from the current position requires too much typing or involves the use of the arrow keys, and it gets worse when I want to move further, I end up using the mouse. Now imagine this same scenario but on a laptop.

I've always considered to learn VIM but the amount of time needed to master it has always made me to step back.

I'd like to hear from people who has learned it and if it ends up being one of those things you cannot live without.

Edit:

At work I use VS2008, C# and R#, which together make editing code a lot faster and easier than ever, but even so I think I could enjoy not having to use the mouse at all.

Edit:

And not even the arrow keys.

+24  A: 

Running through vimtutor only took me 30 minutes, which was enough to get familiar with vim. It was worth every second of it.

RommeDeSerieux
If you know of a better explanitory link, please change mine :)
Blorgbeard
Thanks for the link, upvoted a question from you.
RommeDeSerieux
I hate the vimtutor, it doesn't really teach much. IMO it spends a lot of time teaching less useful stuff.
hasen j
vimtutor is exactly that, a tutorial. I did it everyday for about 10 days. First time it took me about 30min, the next day 20, then 15. By the end of the week, I had most of its command imprinted in my mind. I think rather than trying to memorize, repetition is the best way to approach Vim. 15 min everyday for a week seems like a really small price.
mike
I found vimtutor very helpful and any beginner who wants to learn vim should definitely try it out.
jimiyash
What about once we are done with VIMTUTOR ? What's the next step to learn more ?
privatehuff
+56  A: 

I've been using vi and vim also for some 20 years, and I'm still learning new things.

David Rayner's Best of Vim Tips site is an excellent list, though it's probably more useful once you have some familiarity with vim.

I also want to mention the ViEmu site which has some great info on vi/vim tips and especially the article Why, oh WHY, do those nutheads use vi?.

Greg Hewgill
Yes, I'm always learning new things in it too. Still my favorite editor too.
Craig S
I wonder if that is a good thing or a bad thing. If you constantly learn new things, the learning curve is REALLY steep, features are REALLY hidden and there is no sense of mastery. Anyway, if you wanted RISC, you went with vi instead of vim, right?
BastiBechtold
^ trollish comment
Wahnfrieden
@Paperflyer: I had the same thoughts. If you still haven't mastered it after 20 years, that's a headache I'm not sure I want
Dinah
How so? It means that while it has so much features you can keep learning, but you don't have to learn them all to be more productive.
Arda Xi
+6  A: 

I've used vi/vim for 25+ years. If you already know some command-line editor, then maybe you don't need to learn vi/vim. But if you don't know any other command-line editors very well, it's worth learning it. It's pretty easy to be productive in vi/vim with little effort.

Craig S
+6  A: 

I recently switched to VIM, and I think it's worth it. If you need to "just get something done", you can always stay in insert mode, where vim is (mostly) like a normal text editor.

I've noticed that things that didn't use to bother me, like reaching for the arrow keys, now feel wrong and too much effort. It's definitely decreased my hand motion and usage of the mouse, which is good for both ergonomics and productivity

Gabe Moothart
+4  A: 

It depends what you want to do with VIM. It doesn't make sense to learn it only because many people cannot live without it.

When I was working a lot on UNIX environments, I couldn't live without it. Even when VIM was not installed on a UNIX machine, I could at least use vi. You could always count on it -- even if the machine is not yours (that from the customer).

Now I program in C# and mostly work on windows environment. I have installed VIM on my PC ... and I don't need it.

Evaluate if you really need VIM and if it supports you in your "flow of work". Try it out. Play with it. If you think you need it, stick to it ... the learning curve is very steep.

Theo Lenndorff
+3  A: 

Firstly good vi(m) knowledge will save you the time you have to hustle to do emergency editing of config files on a server under seige. It can hold up on a laggy ssh connection.

Admin stuff aside vim's input method will be your best defence against carpal tunnel if you use it effectively with an ergonomic keyboard.

The best way to see the point of vim is to start a casual project at home, unplug your mouse and tape over your arrow keys.

And read the help

michael
I also find the Vi input model great to defend yourself from the carpal tunnel syndrome...
CMS
+38  A: 

Could I live without it? Easily.

Is it useful? Yes.

Reasons for Learning

  • vi is guaranteed to exist on all Unix systems and exists on most Linux ones as well. That kind of broad coverage makes learning it worth it.

  • It's much quicker to use vi for a sudo edit:

    $ sudo vi

  • Also, GMail uses vi-ish commands for selecting & moving emails around!

You don't have to be a master.

Just learn

The basics:

  • How to switch from command mode to insert mode i
  • How to switch from insert mode to command mode Esc
  • How to navigate up a line in command mode k
  • How to navigate down a line in command mode j
  • How to navigate left a character in command mode h
  • How to navigate right a character l
  • How to save a file :wEnter (write)
  • How to exit without saving (in command mode) :q!Enter
  • How to Undo u
  • You can combine writing and quitting (in command mode): :wqEnter

From there the rest will just make you faster.

Trampas Kirk
I've always used "vi is easy; you use the ell key to move the cursor right" as a humourous (I hope) way to introduce it. But I've been using it a long time and wouldn't be without. Can't claim 25+ years for another couple, yet, though, so no new answer from me.
Jonathan Leffler
This is how I learnt it. Start with the minimum and build a little on it each day. Take the time to learn a slightly better way of achieveing a task. See the "7 habits of highly text editing" for inspiration.
Ben
Gmail, Google experimental search keyboard shortcuts, Slashdot keyboard shortcuts, man, and less all use vim-like bindings. It surprised me to discover I had accidentally learned these without knowing vim! Even Firefox uses / for incremental search (with very slightly different semantics from Ctrl+F).
Adam Rosenfield
"It's much quicker to use vi for a sudo edit" I'm not sure about that, for example TextMate (OS X GUI application) allows you to edit system files normally (Cmd+o, or `mate /etc/blah`), then prompts you for your admin password when you save.. I imagine most IDE's do the same..
dbr
@dbr sadly, I have seen nothing with that feature. Though it would be kind of nice. I did learn a trick with vi to do something similar by pushing its output through sudo tee... now where did I write that down...
Mike Cooper
[:][X][Enter] is the same as [:][W][Q][Enter]
Vitalii Fedorenko
+2  A: 

Two advantages of vi/vim:

  • it is very light-weight

  • it is installed on almost every *NIX system

Colin
why did you put * instead of U?
Kamran
+2  A: 

I think it's definitely worth the time and effort to learn vim. To me, it makes typing and navigating around text so efficient, it's hard to imagine going back to emacs or ctrl/shift/alt/meta key combos.

Don't get intimidated by all the fancy features of vim. Once you've used it enough, you'll figure out which commands you use the most, and you'll figure out which things you can forget about.

Andy White
+2  A: 

The amazing ubiquity of Vim, and the even more amazing ubiquity of Vi-clones in general, on Unix systems alone is enough to make it worth learning.

Besides that, the whole Vi-style thinking is something that I really think has made me a bit more productive. For a person not used to modes such as the command mode and insert mode, it seems a bit excessive to have to enter a mode just to insert text. But, when one has been using Vim for a few months, and has learned quite a few tips and tricks, Vim seems to be an asset that seems to be worth it.

Of course, the Emacs crowd says the same thing regarding Emacs-style thinking, but I gave up on learning Emacs because Vim was simpler and did the job for me.

Rishabh Mishra
+3  A: 

I learnt vi because I had to.

My crazy teacher forced us to learn to program in C using a terminal to an AIX system.

It was a real pain, but worth it.

Today, I only use vi for quick edits or small programs.

When I have to go for a project, I rather use and IDE. In my case IntelliJ idea is very good at the task, because I can code for hours without grabbing the mouse.

I don't know how much shortcuts does VS2008 has, but if they are as discoverable as Eclipse, I think you are in trouble go for vi.

If you DON'T edit code outside the IDE and your IDE has good shortcuts, you better learn those, and then, go and learn vi anyway.

:)

OscarRyz
+26  A: 

If you're a programmer who edits a lot of text, then it's important to learn an A Serious Text Editor. Which Serious Text Editor you learn is not terribly important and is largely dependent on the types of environments you expect to be editing in.

The reason is that these editors are highly optimized to perform the kinds of tasks that you will be doing a lot. For example, consider adding the same bit of text to the end of every line. This is trivial in A Serious Text Editor, but ridiculously cumbersome otherwise.

Usually vim's killer features are considered: A) that it's available on pretty much every Unix you'll ever encounter and B) your fingers very rarely have to leave the home row, which means you'll be able to edit text very, very quickly. It's also usually very fast and lightweight even when editing huge files.

There are plenty of alternatives, however. Emacs is the most common example, of course, and it's much more than just an advanced text editor if you really dig into it. I'm personally a very happy TextMate user now after years of using vim/gvim.

The trick to switching to any of these is to force yourself to use them the way they were intended. For example, in vim, if you're manually performing every step in a multi-step process or if you're using the arrow keys or the mouse then there's probably a better way to do it. Stop what you're doing and look it up.

If you do nothing else, learn the basic navigation controls for both vim and Emacs since they pop up all over the place. For example, you can use Emacs-style controls in any text input field in Mac OS, in most Unix shells, in Eclipse, etc. You can use vim-style controls in the less(1) command, on Slashdot, on gmail, etc.

Have fun!

Ryan Bright
This has a point in it that many people overlook. Almost any repetitive task has a shortcut. Developers love shortcuts. As rbright said, if you find yourself performing a step repeatedly, stop and see if someone's already documented a shortcut.
AvatarKava
You put it perfectly.
jpeacock
+1 for neutrality
jk
My editor is constantly making bad jokes. I should switch.
Greg Graham
+2  A: 

I learned to like vi after watching someone who was very skilled with it navigate around to make edits at an insanely fast clip. You really can code quickly with it. Another reason I like it is that sometimes I find that mousing around in an IDE really hurts my hands after a while and vi provides a nice change. As others have mentioned it's also almost always available on unix systems and works well even over lousy connections.

One thing that I haven't seen mentioned is that knowing vi has the added benefit of "geek cred" in some circles. I can think of at least a few people who chuckle when they see a new programmer fire up nedit to make some changes to a file.

Dana Robinson
+3  A: 

I'd say vim is definitely worth learning. I picked it up last summer, and it is now my editor of choice for just about everything (java is a stretch, but doable when I don't need extensive analysis support). As everyone has already affirmed, it is a wonderfully efficient tool.

For what it's worth, I only learned a fairly small subset of vim's features (which took a day or two) from a graphical tutorial, and a few odds and ends from here (long read), and the search and replace functionality, and I was hooked. I've learned things since then, but at my leisure. I'd say the learning curve flattens out at this point, but then, I was using it pretty heavily and was surrounded by others who were, too.

Ellery Newcomer
+12  A: 

It's definitely worth learning either vim or emacs. It's also worth learning to touch-type. In both cases the reasons are the same: your thinking is no longer interrupted by the mechanical process of getting your code onto the screen.

As to how to start, just dive in and start using vim for everything.

P.S. The emacs-vs-vi debate is endless. I've been using emacs for 26 years. If I started again today I'd learn vim because (a) it's gotten better and (b) there are many fewer modifier keys (Ctl-Alt-V, anyone) and vim users seem to get much less typing injury.

Norman Ramsey
RSI is the one occupational hazard of developers. I never thought of it that way but I bet this is a really good point. It's a lot harder to type chords from a muscle standpoint. I knew there was a killer reason to use vi!
DigitalRoss
I've used both, I was "baptized" with vim, and learned emacs a few months ago. I prefer vim because tasks are broken up - you're either editing or inserting, not doing both. This distinction helps me think about what I'm doing, as well as makes the "normal" commands 1-2 key strokes, instead of 2-4. I just wish vim was Lisp based (and no, viper mode fails to support all my vim standard features. Yes I could roll my own, but then I'd be missing them any time I touched a new computer/system)
Wayne Werner
+14  A: 

Nope, skip it. Stick with your hand-holding, memory-sucking, RSI-inducing IDE and stay away from my job opportunities!

jpeacock
hand holding is a good thing in an editor - just because vim doesn't have it doesn't mean it's a bad thing
Wahnfrieden
I think hand-holding makes you more productive as a programmer, but I also think it makes you a not-as-good programmer because you don't have to *know* the language, you can just guess/use the crutches.
Wayne Werner
+1  A: 

Don't be scared off by the number of commands, I've not met anyone who used more than a couple dozen at most. I find it indispensable, because when I'm thinking about code I'm thinking about text, moving to thinking about mice just messes me up. The big tricks, I think, are to learn it a little at a time, and don't be hesitant to play around - the undo features is great for exploring its behaviors.

Also, if you get deeply into it, vim is scriptable. The possibilities are literally endless.

(Yes, all of this applies to emacs too...)

Kim Reece
+1  A: 

I was happy at my textpad and ecplise world until i had to start working with servers running under linux. Remote scripting and set up of config files was needed!

It was hard at the begining but now i can easily set up and tune up my servers.

Cesar
+2  A: 

I am maintaining a very big linux project on the remote computer. There is no choise to use Eclipse or similar GTK based IDE. I've been working there for 3 years. And I set my vim just for this project. And still tweaking.

Now I can do any thing from the Vim: source control, sql, debug, compile, browsing - really fast browsing over 1Gb source code.

Visual Studio or Eclipse couldn't handle all of this. And If I had a choice I would'n change Vim to other editor or IDE.

Mykola Golubyev
+2  A: 

I'm in the same situation as you, and as a beginner to Vim I originally found it a little daunting - the learning curve seems steep. From what I've learned in just a few hours I'm already feeling like I won't be able to live without it.

Here are a few links that I've found for useful Vim screencasts to show you what it's capable of.

A good bit of advice that Bram Moolenaar (benevolent dictator of Vim) gave in that last link is that it would be inefficient to try to learn every single command and function, just figure out what it is that you're doing that isn't working very well, look for a way to make it more efficient and then make it a habit.

Andy
+1  A: 

You might want to learn vim because you might not be happy with the editors you're already using.

You might want to learn vim because many people say it is cool. Just look how many answers you've got to this question.

I will provide an additional reason for learning vim. It has a reputation for the quality and the completeness of its docs. So you will find most answers to your questions in its help system as soon as you will manage to stick the proper keywords in your help queries.

Anonymous
+1  A: 

Yes: If you don't use and don't plan to use any IDE in future. And even if you use an IDE you will find yourself returning to it to do many things. In vim you van write scripts, do complex tasks like instead of individually editing 500 lines do it with a (slightly cryptic but easy to understand once you pick up) command. I initally found it difficult but later it has helped me lot. Even the best IDE's editor will lack the power of vim. Vim can work well with CVS, SVN, make, debuggers etc.

No: If you will stick to IDEs like Eclipse or Netbeans. Or if you find that editors like Kate are enough for you. Infact Kate or Notepad++ or jEdit have GUI and features you may miss in vim. e.g. Kate's symbol viewer or Notepad++'s huge menu bar.

Xolve
+2  A: 

To learn vi(m) fast one must first understand the whole design. Vim has a great set of cursor-movement commands, check a few (X is a character, # a digit):

j k enter arrows 0 $ w W b B ctrolD crtolU ctrolE ctrolY H M L fX FX tX TX , ; % gg G n N mX 'X ''

and many more it would be boring to enumerate. Many of these support a count before the command, like 4j to move 4 lines up.

Now, back to the design, you type a command like d for delete followed by a cursor movement and the command applies to the piece of text from the cursor position till the movement end. For example H moves to the top of the screen, dH deletes to the top of the screen and cH changes (replaces) to the top of the screen.

This design is quite powerful. It also reduces, or organizes, what you need to learn. Definitively the first step is to learn a few cursor movement commands. Say,8 or 10 at first. Then you are almost done.

+4  A: 

I use VIM pretty much exclusively now.

I used to use Vim for editing and VS Editor for debugging. This probably seems a bit crazy, but I found the Vi paradigm (macros, home key based editing etc) such a boost to my productivity, that editing in VS was paintful.

Thanks to Viemu, I don't even have to do the switching any more. It is not the perfect solution yet (code completion is sometimes not as elegant as in native vim and the macro recording isn't perfect), but it is much better than switching back and forth constantly.

The learning curve for Vim is probably exaggerated. I think once you get into it, it is pretty intuitive.

Cannonade
+1  A: 

Learning something new is always worth the effort, IMHO. I suggest you print out a cheat sheet and force yourself to use it day-in and day-out.

switchmode
+1  A: 

Personally,

I find many of these terminal text editors incapable at times. Would I invest time picking one up? Absolutely! I would continue to learning one along side a IDE. Of course in the end, it really comes down to preference.

Rev316
+1  A: 

Vim is definitely worth learning to partly summarize what has been stated previously here are the main reasons:

  • Vi/Vim can be found on most unix systems.
  • Vim allows you to easily code without taking your hands off the keyboard.
  • If you plan you configure anything in a unix based system likelihood is you going to be editing a fair few config files, therefore you'll want to learn a terminal based editor, of which vim is one of the best (sorry emacs).
  • Vim compiles/has precompiled binaries for almost every OS out there. No need to post "I need a textmate alternative for [insert OS]", you'll have Vim instead!
  • There are a lot of good plugins out there to add alot of functionality, such as in-editor cvs diffs, although some of these require a fair amount of tinkering.

Also on a side note if you find you like the Vim key bindings, there are also IDEs which include vim bindings in their editors for simple commands, for example Komodo Edit.

For help on learning Vim, try typing 'vimtutor' into your terminal and follow the instructions. There is also a book which is particularly good Hacking Vim

Jamie
+1  A: 

No. Learning vim is worth more than the effort.

ojblass
+2  A: 

I learned Vim. It wasn't too much effort. Now I absolutely love ci" ci( cw V:s/from/to/g

thomasrutter
+2  A: 

I too put off learning vi or vim for many years. Matter of fact, I use to make fun of the "vi guys" who always seemed to be doing finger aerobics. Then, as I moved away from Windows and over to Linux as my primary OS, I had to become more familiar with vim. It was a learning curve and it still is. After 9 years of using vim on a daily basis I still find myself learning new and faster ways of doing things. What I use to think of as "finger aerobics" actually turned out to be an extremely efficient way of being productive. I can now do a whole lot more code development in a whole lot less time and effort than I ever did prior to vim. And as I'm sure you know vim runs on about every platform out there so you always have it when you need it. Also, if you like GUI's they have GUI versions for most platforms. Personally, just like the mouse, I don't want to see a menu bar, scroll bars, etc. cluttering up my editing window(s).

If you decide to give vim a whirl I would highly recommend the O'Reilly "vi Editor Pocket Reference" book. It's cheap and it's great if you're just learning vi (vim). The full blown vim books are also good but the pocket reference gives you all the basics to be productive quickly.

+2  A: 

Yes, definately take the time to learn at least a bit of 'vi' and 'vim'. It travels very well.

You'll never be stuck when you are faced with a customer Unix/Linux/Mac system that you don't have install capabilities for. Even on Windows (if you do have install capabilities) 'Vim' is free and easy to install. (As opposed to investing your learning curve purely in something like UltraEdit, which although an excellent editor might not be available for you all the time...).

Learning vi can set you up for learning other tools like 'sed', and regex in general: stuff that is generally transferable.

Plus if you want to be a proper geek, you just simply need to know 'vi/m' or you'll look like a faker ;-)

monojohnny
+2  A: 

It is definitely worth it to learn Vim. It takes a little ramp up time to get used to modal editing but ever since it became comfortable I have been amazed at how much faster I can work in Vim and how much I miss "the Vim Way" when I'm stuck in a another editor. I got up to speed with Vim's core commands using slide decks as flash cards. I've posted them if you want to check them out. They cover the core commands you'll need to get up and running.

http://www.adamlowe.me/2009/07/vim-cards-how-i-learning.html

Adam Lowe
+1  A: 

An investment in learning VIM (my preference) or EMACS will pay off.

I suggest visiting Derek Wyatt's site, running through the VIM Tutor, and checking out the Steve Oualine PDF book.

Vim helps me move around and edit quicker than other editors I've used. My work IDEs are quite limited in what they allow one to do and are typically devoted to a particular environment. There are tasks that still require me to revisit the IDE (such as debuggers which are a compiled part of the IDE).

modal
+2  A: 

My job forced me to pick up vim and it has quickly become second nature. Now my complaints are about IDE's that do not have vim emulation or plugins. I do notice that the esc key has become my enemy outside of vim.

I did find several emulators for vi within Visual Studio:

http://code.google.com/p/vim-visual-studio/

Courtland
+1  A: 

It's definitely worth the effort.

There's one obvious reason that anyone who uses Vi(m) will tell you, and two others that people never seem to mention.

Here's the obvious one:

  1. vi is at once ubiquitous and incredibly powerful, and by learning it once, you gain the ability to exercise that power on pretty much any computer that has a keyboard.

And these are the lesser known reasons to learn Vim:

  1. It's not half as much effort as you think it's going to be. Run through the Vim tutor once (vimtutor at a shell, or in Windows run it from the Vim folder in the Start Menu), and you'll already be well on your way to competence, and it's all downhill from there. I was up to the level where I could use Vim at work without taking any noticeable productivity hit within less than a week's worth of lunchtimes.

  2. It's fun! Editing text is like a game to me now. I actively enjoy it--which is pretty ridiculous, when you think about it.

There's also two good reasons not to learn Vim:

  1. It's addictive, and you'll find yourself wishing you could use Vim commands in all your computing, and cursing whenever you can't. Fortunately, at least for some situations, there's ways to get around this.

  2. Again, it's addictive, and although you won't lose any productivity from actually using Vim, you will waste hours searching for good tips to make your Vim experience even better, and reading the Vim tag on Stack Overflow.

Rich