Pivotal Labs

Column Edit Mode in VI

edit Posted by Brian Takita on Thursday December 27, 2007 at 07:50AM

I've found that typing in column mode to be very useful when using editors like IntelliJ or TextMate. VI also has a column edit mode, that is a little tricky to use.

To use it, press:

  • Ctrl + V to go into column mode
  • Select the columns and rows where you want to enter your text
  • Shift + i to go into insert mode in column mode
  • Type in the text you want to enter. Dont be discouraged by the fact that only the first row is changed.
  • Esc to apply your change (or alternately Ctrl+c)

You will now see your changed applied.

Comments

  1. matt matt on December 27, 2007 at 05:26PM

    you guys are so helpful. pivotal is the best

  2. Mark Wilden Mark Wilden on December 27, 2007 at 08:35PM

    Brian, can you give an example of where this capability (inserting the same thing in front of a number of lines) would be used?

    For example, I could imagine using it to comment out some lines, but without "comment-in" capability, that wouldn't be helpful.

    ///ark

  3. Garry Garry on December 27, 2007 at 11:01PM

    Mark,

    I use column edit mode for comments, mostly (since Ruby doesn't have block comments). After the 'shift-i' I just type "# " and ESC (or ctrl-c or ctrl-[)

    It is also useful to indent a block of lines forward/back. There are other ways to deal with block indenting, but I tend to use column edit probably b/c I just haven't build muscle memory for the other methods.

  4. Will Leinweber Will Leinweber on December 28, 2007 at 06:27AM

    Garry,

    Ruby does have block comments:

    =begin
      this is all
      commented out
    =end
    

    I've rarely seen them ever used though.

  5. Brian Takita Brian Takita on December 28, 2007 at 06:51AM

    Mark, If I understand you correctly, you can comment in by

    • going into column select mode
    • selecting the block you want to delete
    • press x
  6. Shep Shep on December 28, 2007 at 04:51PM

    Also hitting "v" in VI will get you into Visual mode which is also very helpful if you need to change lines rather than blocks.

Add a Comment (MarkDown available)