XHTML-CSS.com

This is our blog. It's mainly about programming, web developement and design, social web, coding habits and advice and miscellaneous geekery. You can subscribe to the feeds to never miss a bit.

Seven Reasons Every Programmer Should Use Vim

Permanant link —Jan 15, 04:05 PM

Over the last few days, I heard so many people talking about how it’s so “has been” to use vim or another text editor for there’s a lot of IDEs out there. Let me clear this once for all : I I’m not insulting people who use IDEs, I’m not against IDEs. They’re not my choice, I have used several, tried a lot, and still stick to my editor of choice: VIM ! French people say: “Il n’y a que les imb√©ciles qui ne changent pas d’avis”, which means: “Only stupid people don’t change their mind”, but still… I’ve choosed my tools and from my experience, I just can’t find better.

Don’t believe me? Let me show you some very nice things one can use in vim easily and have a great coding experience:

1# Vim speaks the same language as you

Do you find yourself talking to yourself while coding? Saying something like: “paste this here, delete this, change every X with Y”? Yes you do! Even if you don’t pronounce these phrases, you think them :) vim is written in a way that when you think of an action you can easily type it.

Examples:

Copy 3 lines, move 3 lines down and paste:
3yy 3j p (yy is for “yank or copy line”, “3j”: move down by 3 lines and “p” is for paste)

d3w : *d*elete 3 *w*ords
y4w : *y*ank 4 *w*ords
d$ : *d*elete everything to the end of line
viB: select (*v*isual) *i*nternal *block useful for selecting a block of instructions

VIM user vs. IDE user

2# Moving: if IDEs walk, vim swings

We don’t write code from the first character to the last one in a single pass, no one can do that! That’s why we say: “editing” files. We move through our code, change things, improve others and so on. Smart coders know that moving smartly in their code is saving a lot of time. And vim offers a wide variety of moves possibilities inside your code, that sometimes with just a single keystroke you can go forward or backward looking for something instead of scrolling.

Examples:

Star and sharp: In normal mode you can use * and # to search for the word under the cursor. * searches forward for the word, while # searches backwards.

The % key: to jump to a matching opening or closing parenthesis, square bracket or a curly brace.

f followed by char : moves you to the next occurrence of char, and F does the same backwards.
G: end of file

Search don’t scroll: like gmail’s motto (search don’t sort) You can smartly move inside your code by looking for words, characters, phrases… and this could be done very easily. No dialog boxes to nag you, no buttons to click, no mouse to move, only type “/” for looking forward and “?” for the other direction.

3# THE greatest search and substitute power ever!

Basically search and replace in IDEs prompt you with a dialog to input text, check radios and then click on search or replace. And this is just the basic case, IDEs with regex find/replace have very scaring dialogs! Vim doesn’t need dialogs for this. Everything is in the command line. And boy! What a power! Writing the whole search and substitute features of vim would be a manual not a blog post.

VIM and IDE search/replace features

4# THE best customization features ever!

Ok, every IDE out there come with many customization features too, but vim is the best in this field. In fact, vim’s key mapping are elegant and very powerful, color schemes are infinite, there are a lots of plugins, more than you ever dreamed of. You can write your own function to do what you want in vimscript and you can write your own plugins in your prefered language if you want (python, ruby…)

5# The weight and portability.

Vim is light, IDEs are not. Yes, some IDEs are available for the 3 main OSes too, but can you use eclipse with ssh easily?

6# The challenge and the pleasure of learning.

During my first steps with vim, I asked in #vim IRC channel how can I easily remember to type ESCAPE to go back to normal mode, and someone gave me the best answer one can give: “you’ll make errors, you’ll type “:w” in insert mode, this will hurt you every time, this will burn your fingers, but you’ll learn. And this is very true. Vim has a very steep learning curve for someone used to IDEs and mouses, but the more you use it, the better you’ll feel. It’s very rewarding to see that YOU can itch what YOU want in YOUR memory. You’ll learn with vim how to learn good habits.

7# Minimalism and surviving

When you’re used to vim, you’ll be able to use any IDE on this planet, you’ll use them maybe better than people that are used to them. Notice that most IDEs ended by integrating the ability to use vim in their editors… such decisions can’t be wrong. Second, wherever you’ll be you can work on your code, because you’re not addicted and limited to IDE XY. You’ll survive.

That’s it folks, go ahead and learn vim. I bet, and will win the bet, that if you give vim a real try — and by “real” I mean really wanting to learn and not giving up at the first command you’ll see inserted in your text instead of having it executed — I bet you’ll love it! All these monkeys that used vi and still use vim can not be wrong.

Funny Thing

EDIT: Just discovered this on bash.org : Everyone’s first vi session?

Some vim resources:

Worth it?: Please digg it

P.S. Please, bear with me on my poor English, if you notice any error please report it to me and I’ll correct it and btw improve my English which is my 4th langage


Enjoyed this post? please subscribe to our feeds to stay informed.

Comment [9]

— pentolino · Jan 16, 05:56 AM · #

Thanks for this article, very informative! I will defeat my lazyness and switch to VI one day, promised!

V V S Kumar · Jan 16, 06:07 AM · #

Hi,
That was a very funny post about vim usage though a very useful one. I don’t know why are you so crazy about IDE users but still I liked your sense of humour in explaining and justifying your statement. I agree to your point (which I assume I’m correct by seeing your cartoons) that using editors such as vim, we remember a lot unlike in IDEs everything we should depend on the tools provided by the IDEs.

So the conclusion is that it is a very funny but a useful post to read on.

— Juraj · Jan 16, 06:07 AM · #

Hello, I’m very happy you love your editor so much, it’s very rare to be so enthusiastic about any program whatsoever. But I think programming is not only editing code, but all that stuff which surrounds it, and that’s why we have IDEs here. Even though it can’t do amazing geek things like vim, it makes software development much easier.

— Gregorio Melo · Jan 16, 09:58 AM · #

Well, I agree with the point that vi can improve the edition of the code… but IDEs are very helpful when you think about refactoring, (re)deploying apps, versioning, debugging…

vi is great for editing code though. There is no better editor. Editor.

Great post by the way!

Paul Davis · Jan 16, 10:15 AM · #

Don’t forget how it can save you ‘posterior’ when you need to log into a server on some slow dial-up just for a minor edit to a file……

I’ve known people who’ll just drive into the office to do that.

admin · Jan 16, 12:35 PM · #

Thank you folks!

@pentolino : You’re welcome! Go ahead, you won’t regret it! :)

@Juraj : thanks for the precision, indeed programming is not just about editing, but there’s plenty of plugins that enhance vim’s basic features. And won’t you agree that coding is editing too… and if we can ease that part (editing) with a better tool let’s do it and concentrate on more “intellectual” stuff.

@Kumar, @Gregorio: unlike anyone might think I’m not mad at IDEs, they’re just not my cup of tea, and I encourage everyone to use if they choose to stick with thier IDE, a vim plugin for the text edition.

@Paul, Oh yes! I find it extremely useful to just edit files over ssh with vim. No FTP, scp… download/upload needed! :)

jbj · Jan 16, 04:46 PM · #

Great post! Vim is my editor of choice too.

Vim Rocks · Jan 17, 12:08 AM · #

I did not make the jump from vim to IDE’s until a few years ago. I could not ignore IntelliJ. What was the first plugin I installed? A vim plugin.

I tried Eclipse and even paid money for the vim plugin there, but like most plugins that come with Eclipse (free or not), they simply don’t work.

An editor is one thing, an IDE is another. They are not mutually exclusive.

An Jay · Jan 17, 03:40 AM · #

Funny post. I like this.

Commenting is closed for this article.

« Previous post:
Next post: »