In a script, I want to delete a rectangular block of text. For example, I want to convert this:
ABCD
EFGH
IJKL
MNOP
into this:
ABCD
EH
IL
MNOP
One way to do this is with visual block mode. Move the cursor to "F", enter visual block mode with Ctrl+V, move the cursor to "K", and press d.
However, this has the side effect of changing the value of the '<
and '>
marks. It there a way to avoid doing this? I want my Vimscript function to have as few side-effects as possible, other than deleting the desired text.
I wonder if there is a way to restore the '<
and '>
marks to the value they had before my function was called. Or, alternatively, if there is a way to delete a rectangular selection without entering visual-block mode in the first place.
:s/..\zs.*//
to keep only the first two characters in the line (use a range to control which lines)... many options. I’ll try to write an answer when i find out about the marks.