Reputation: 6063
I would like to remove the content for all lines between two columns. How do I do this?
For example, I want this:
abcdefg
hijklmn
opqrstu
To become this if I remove text between columns 3 through 5:
abfg
himn
optu
Upvotes: 8
Views: 12710
Reputation: 166419
I would do in the following way:
:%s/^..\zs.*\ze..$//g
which will remove everything else apart first two columns at the start, and two at the end.
Upvotes: 0
Reputation: 2738
Your question is very similar to this one.
To delete the columns 3 through 5 for all lines in the file:
:%normal 3|d6|
In order to delete an specific line interval (80 to 90), use this:
:80,90normal 3|d6|
If you're not familiar with the normal command nor with the | "motion" there goes a quick explanation:
normal
command execute the following commands in the normal mode;3|
moves the cursor to the 3rd column;d
) until the 5th column (6|
).Upvotes: 8
Reputation: 3288
You can use search and replace:
:%s/..\zs...\ze
or in a more general form:
:%s/.\{2}\zs.\{3}\ze
where the first number (2) is the index of the column (zero based) and the second number (3) is the count of characters the column has.
Explanation:
:%s/
search and replace in the whole buffer.
.\{2}\zs
find two characters and set the beginning of match here.
.\{3}\ze
find three characters and set the end of match here.
Omit the replacement string since you want to delete the match.
HTH
Upvotes: 3
Reputation: 172570
For spontaneous editing, I would use blockwise visual mode via CTRL-V (often mapped to CTRL-Q on Windows), then d
to delete it.
If you do this often, for a large range / the entire buffer, or repeatedly, I would use a substitution that starts matching in a virtual column, and extends (up) to the end column, like for your example:
%s/\%3v.*\%<7v//
Upvotes: 4