30
votes

I'm considering whether I should start using VIM again instead of an IDE. What are the most useful features of VIM that aren't standard in an IDE?

8
  • 3
    Which IDE do you use? Many IDEs have VIM plugins so you can edit as if you were using VIM. Sep 7, 2010 at 23:15
  • 2
    @Brian: Surely they didn't emulate all of the advanced features?
    – Casebash
    Sep 7, 2010 at 23:36
  • 1
    Probably not all but the ones I've used are great for VS. There are at least 2 of them. viemu.com and github.com/jaredpar/VsVim Sep 7, 2010 at 23:37
  • 2
    @Brian R Bondy: None of them even come close to covering all of vim's features. They scratch the surface and don't really do any more
    – Daenyth
    Sep 22, 2010 at 22:54
  • 2
    Or you could be really sensible and start using emacs instead. ;-)
    – Orbling
    Dec 22, 2010 at 13:41

16 Answers 16

32
votes

I don't think its necessarily the advanced features of VIM that make it so powerful. Its the fact that you never have to take your hands off the keyboard to do anything. Finding something in a huge file is as simple as a couple of keystrokes. Opening and closing multiple files in the same window is incredibly fast as well.

While it may not seem intuitive at first, its well worth your time. Even if you don't use it as your standard IDE (I generally use Visual Studio or Eclipse, for example), you'll find your self using VIM to quickly open and edit files because it becomes way faster than waiting for the IDE to load.

Invest the time to learn how to use VIM well and you'll never regret it. I'd say its comparable to learning to touch-type.

2
  • 3
    This answer is probably the most useful feature for Vim, it is also one of the only. Anything programmed for Vim can easily be applied to IDE's too, it's just text processing after all... Sep 15, 2010 at 12:07
  • 4
    +1 Whilst I am an emacs devotee, the same argument applies. The modern IDEs are far too "graphical", for text editors.
    – Orbling
    Dec 22, 2010 at 13:42
22
votes

For me the :global command is a killer app. It will execute arbitrary vim commands on any line that matches (or does not match) a regex.

Here are some examples:

The default behaviour is to list out every line that matches, so:

:g/TODO:/

will list every line that contains the text "TODO:"

change 'Mickey' to 'Minnie' on any line that also contains the word 'Mouse'

:g/Mouse/ s/Mickey/Minnie/

The commands can have their own range, so this will delete from every line with "TODO:" to the next blank line:

:g/TODO:/ .,/^$/ d

Use :g! to execute on every line that does NOT match the regex, e.g. to replace "emacs" with "vim" except on lines that contain the word "sucks":

:g!/sucks/ s/emacs/vim/
2
  • Great tricks with global command ! I had never thought of using them like that.
    – Xavier T.
    Apr 14, 2011 at 9:47
  • Eclipse supports regex searching of files, either as individual files, projects, or across projects in the same workspace. Regex replace is also supported to some extent, but I believe vim has a much more powerful regex capability.
    – Thomas Owens
    Aug 18, 2011 at 11:40
16
votes

I find the ability to delete everything in between a set of paired symbols incredibly useful. For example, quite often, I'll find myself wanting to replace a string in the code. So, di" while the cursor is in the block will delete the string, while keeping the "" intact, and put the cursor in between the two quote characters. da" does the same thing, but deletes the quote characters too.

1
  • 12
    Even better, ci" deletes, and puts the cursor in insert mode so that you can immediately start writing. Dec 22, 2010 at 18:35
9
votes

'Insertion mode keyword completion'. Ctrl-P and Ctrl-N in insert mode to search through the text to try and complete whatever variable name you are typing. I've never seen this in any other IDE and I really miss it. Code completion in IDE's just isn't the same.

4
  • 2
    You also have proper code completion if you want, using omni-complete. ^X^O omni-completes in insert mode, if you have it enabled. But you're right, I find myself using keyword completion far more than omni-complete. Sep 15, 2010 at 11:41
  • @Chinmay: I think you have the meaning of "proper" backwards. Proper code completion completes anything using the principle of locality, even if you are writing text instead of code.
    – ninjalj
    Sep 26, 2010 at 21:40
  • SlickEdit has a similar feature; and it's very IDE-like
    – user281377
    Dec 22, 2010 at 12:26
  • 8
    I disagree completely. Modern IDEs (Visual Studio, Eclipse, …) have a kind of code completion that rivals (and in fact surpasses!) Ctrl-N easily. If you haven’t seen this in IDEs, look again at the current versions. And Omni-Complete unfortunately doesn’t work properly. Dec 22, 2010 at 18:33
8
votes

Another feature I find incredibly useful is the ability to change indentation. :15,30>> indents all lines from 15-30 (inclusive) twice, while :15,30<< de-indents the same lines twice.

2
  • While I love the feature, pretty much every IDE has block indent (and dedent). Aug 18, 2011 at 16:06
  • I find = to be just as, if not more, useful than << and >>.
    – greyfade
    Sep 14, 2011 at 18:44
6
votes

the command dd (delete current line). I use this one so much.

Also, being able to type something like 3dd and delete the next 3 lines is wonderful. I've never seen this in another editor =D

8
  • Netbeans almost has this, ^X with no selection will cut the current line. Oct 3, 2010 at 19:39
  • @Alan: No, NetBeans has jVi :) Oct 24, 2010 at 17:30
  • ^K deletes the line and ^u3^k would delete 3 lines in emacs. shift-delete does the same in visual studio.
    – Raoul
    Nov 29, 2010 at 12:46
  • Alan: dd also cuts the current line in that sense that it can be inserted with p later
    – user281377
    Dec 22, 2010 at 12:27
  • 3
    @Raoul, we know there's an emacs series of n 3-keys combinations to replicate every vim command - still, 3dd is poetry. Dec 22, 2010 at 13:18
6
votes

The c command. For example, ci" to change inside quotes. cw to change word. Lots of handy tricks with it.

5
votes

The . command. It repeats the last command.

1
  • +1 to this, and to all other macro-related functionality.
    – P Shved
    Sep 14, 2011 at 20:11
3
votes

Esc ! } will shove the current paragraph off to a command line filter like fmt or wc or which and return results to the editor.

0
3
votes

Rapid access to the command-line. CTRL+Z or :wqa will get me a command line in less than 1sec without my hand leaving the keyboard.

3
  • 1
    +1 That last little bit is the crucial section for pretty much all the benefits: without my hand leaving the keyboard
    – Orbling
    Dec 22, 2010 at 13:45
  • ... Or :!/bin/bash. I use :! quite frequently.
    – greyfade
    Sep 14, 2011 at 18:45
  • I usually use :sh Sep 14, 2011 at 22:08
3
votes

That I can use hjkl to move the cursor without having to leave the homerow of the keyboard. I have most programs (such as PDF readers), which let you change keybindings, set to use Vim movement keys for scrolling etc.

1
vote

This is rather hard to answer, due somewhat to the vagueness of the question, and somewhat to the fact that IDE's differ, and many provide features that other don't (and the fact that I've just a few of them).

However, what I believe distincts Vim from other editors (yes, even Emacs, on this one) is that it is really a great editor. I've in the passing of time, used many editors, and can honestly say that very few come with such a complete set of features for manipulating text, like Vim does.

My style of manipulating text for example, includes very often use of (line/selection of several lines) duplication, and moving (line/selection of several lines) up and down, for which I've long ago defined quick shortcuts. I miss those features in most IDE's (although I've heard ReSharper for VS has something similar).

1
vote

Did you know that there is a vi plugin for eclipse? It costs 15 euro (20ish US$) but it is so worth. No more dd in the middle of a document, and missing all the tiny useful things.

Perhaps a bit off topic but I thought it was worth pointing out.

0
votes

Depending on what you language you are programming, stick with the ide, or get the ide that offers the most refactorings that you can find, get resharper for visual studio if you are doing c#, intellij for java, or visual assist for visual studio, max out the refactorings in eclipse or netbeans.

We should be moving from manipulating text to manipulate code, refactoring tools give you that ability. If vim does give you all the features fine, I for one don't really want to deal with a text editor anymore

1
  • 3
    This is pretty much nonsense. Yes, refactoring is an important tool, but the code doesn't write itself. A good text editor contributes far more to a programmer's productivity than a good refactoring tool. Sep 14, 2011 at 19:20
-1
votes

Table Column Select

This doesn't seem to be in the popular IDEs, and if it is they keep it well hidden. This is really handy for testing regex against a column in CSV data file.

-3
votes

Most IDEs don't allow you to split the screen. I love that feature in VIM.

4
  • 5
    Most IDE's don't? I think most actually do so, at least those that I have used.
    – Anto
    Jan 17, 2011 at 19:52
  • Can you give some examples? Feb 10, 2011 at 19:17
  • 1
    Most IDE's handle screen splitting differently than Vim/Emacs. They do it with tabs usually. These are harder/impossible to manipulate with the keyboard (compare having 50 files open in Emacs vs. having 50 files open in Eclipse and you'll quickly see Emacs win).
    – jsternberg
    Aug 18, 2011 at 18:28
  • Most IDEs that do have splitscreen don't provide easy methods of navigating/adjusting a-la <C-w> Nov 14, 2011 at 19:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.