Change all characters in a column over multiple lines
Asked Answered
S

7

14

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.

Svetlana answered 6/5, 2011 at 20:2 Comment(0)
P
8

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.

Pith answered 6/5, 2011 at 20:5 Comment(2)
Please explain the solution here, do not just link to it.Sheepfold
The current location of the article is blog.pivotal.io/labs/labs/column-edit-mode-in-vi but the answer is too short to fix it.Sheepfold
F
10

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.

Foretooth answered 6/5, 2011 at 20:6 Comment(0)
P
8

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.

Pith answered 6/5, 2011 at 20:5 Comment(2)
Please explain the solution here, do not just link to it.Sheepfold
The current location of the article is blog.pivotal.io/labs/labs/column-edit-mode-in-vi but the answer is too short to fix it.Sheepfold
C
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?

Commutator answered 6/5, 2011 at 20:6 Comment(0)
U
1

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

Underpants answered 6/5, 2011 at 20:6 Comment(0)
S
1

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

Struve answered 6/5, 2011 at 20:11 Comment(0)
G
0

In your special case:

:% s/a/

does the job.

Gustafsson answered 2/9, 2013 at 11:31 Comment(0)
B
0

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

:%s/:./:
Borges answered 9/2, 2020 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.