13

I'm not sure how to explain what I'd like to do, but I've seen this in Textmate and it was quite useful. Let's say I have this text:

:aa => foo,
:ab => foo,
:ac => foo,
:ad => foo

Now I want to select all first characters of the keys (the 4 'a' in the lne) and remove them, so that the result looks like this:

:a => foo,
:b => foo,
:c => foo,
:d => foo

Some kind of visual mode accounting columns not lines.

shgnInc
  • 2,054
  • 1
  • 23
  • 34
Lennart Koopmann
  • 826
  • 1
  • 8
  • 14

7 Answers7

9

Use Ctrl+V to enter blockwise visual mode. You can then select a block of text using the normal movement keys and press x to delete it. I will perform a multi-line insert.

See :help ^V and :help visual-operators in vim for full details.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
7

Use vim in column mode. To use it, press:

  1. Ctrl+V to go into column mode.
  2. Select the columns and rows where you want to enter your text.
  3. Shift+I to go into insert mode in column mode.
  4. Type in the text you want to enter.

    Note: Don't be discouraged by the fact that only the first row is changed.

  5. Esc to apply your change (or alternately Ctrl+C).

You will now see your changed applied.

Source: Column Edit Mode in VI.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Marcin
  • 1,429
  • 8
  • 16
  • 3
    Please explain the solution here, do not just link to it. – Tgr Mar 06 '16 at 02:49
  • 1
    The current location of the article is https://blog.pivotal.io/labs/labs/column-edit-mode-in-vi but the answer is too short to fix it. – Tgr Mar 06 '16 at 02:50
2

Use Ctrl-V to select in block mode, then directional and editing commands to do the rest. See How to remove quotes surrounding the first two columns in Vim?

Community
  • 1
  • 1
Alanyst
  • 1,390
  • 7
  • 10
1

You're looking for Visual Block mode, which is accessible by Ctrl+V in Normal mode. Works just like Alt+select in TextMate.

Austin Taylor
  • 5,437
  • 1
  • 23
  • 29
1

As others have said Ctrl-V is the answer. For a tutorial see Vimcast episode "Selecting columns with visual block mode"

nathan
  • 5,513
  • 4
  • 35
  • 47
0

In your special case:

:% s/a/

does the job.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
PeMa
  • 1,559
  • 18
  • 44
0

You can also use a search and replace to specifically remove the first letter of the lines that start with a colon:

:%s/:./:
Sander Vanhove
  • 995
  • 4
  • 11