Alex Rivera | Logout

What can I do in VIM that I can't already do in Visual Studio?

Asked 2010-07-16T20:31:12.237
18

I heard it takes 30 days minimum to get comfortable with vi. I'm on day 2 hehe. Right now, I seem to be merely memorizing different shortcuts for things I already did in Visual Studio (incremental search, prev/next word, etc.).

So far the most powerful aspect seems to be the numeric keys combined with commands (5 * next line), and the idea of normal/insert modes.

There are a few things I miss from Visual Studio. Ctrl-Click'ing the mouse for quick copy and pasting is probably the biggest.

So that I don't get discouraged, can you guys walk me through some things in vi that you do regularly that can't be done in Visual Studio? It'll help me focus on what to learn and help me develop better habits.

Edit
Report

3 Answers

8

Note that I don't use Visual Studio, and know little about the available features in it. The following are examples of what I find useful in Vim, not a list of missing features in Visual Studio.

Macros

It's easy to create macros for complex (but repetitive) operations. To illustrate with a simple example, let's say we start with:

Line1
Line2
Line3
Line4
Line5

Now we want to envelop each line in a print(""); statement.
Place the cursor on the first line, and enter:

  • qx to start recording a macro to the register x
  • Shift+I print(" Esc    to insert text at the beginning of the line
  • Shift+A "); Esc            to append text at the end of the line
  • j to go down one line
  • q to stop recording the macro
  • 4@x to execute the macro in register x 4 times

See :help complex-repeat for more info on Vim macros.

Text objects

Note that this is one of the improvements Vim has over the traditional Vi. If it doesn't work, you're probably running in Vi compatibility mode; use :set nocompatible to enable the full functionality of Vim.

Text objects allow you to easily select regions of text. Let's say we start with the following text, and place the cursor on some text:

<b><i>some text</i></b>

Now we want to delete everything between <i> and </i>. This can be done by simply typing the command d

answered 2010-07-17T20:14:10.070
6

This article is what got me started on Vim, and I never looked back:

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

It has some great examples on Vim's power.

answered 2010-07-16T22:16:18.557
2

Visual Studio's regular expressions are a little bit Mickey Mouse. Vim has the full POSIX regular expression language at your fingertips.

answered 2010-07-16T20:35:39.057

Your Answer