I have a code segment like below.
type Account struct {
Id int
UserId int
Name string
Address string
City string
State string
CountryId string
}
I want to delete all the data types. Is there a key combination to this?
I tried <C-V>
and select the first letter of all data types in a vertical line, hoping d + $
would work post that, however vim only takes the first input d
and deletes the first letter.
The command dw will delete from the current cursor position to the beginning of the next word character. The command d$ (note, that's a dollar sign, not an 'S') will delete from the current cursor position to the end of the current line. D (uppercase D) is a synonym for d$ (lowercase D + dollar sign). Save this answer.
Use <C-v>
to enter visual block mode, select the lines you want to change and then D
to delete until the end of those.
From :h v_D
:
{Visual}["x]X or *v_X* *v_D* *v_b_D*
{Visual}["x]D Delete the highlighted lines [into register x] (for
{Visual} see |Visual-mode|). In Visual block mode,
"D" deletes the highlighted text plus all text until
the end of the line. {not in Vi}
Note that, as mentioned in the help, X
and D
are not equivalent in visual block mode (X
only deletes the current selection, not until the end of the line).
You can move to the left brace, press the %
key and issue:
s/ \+[^ ]* *$/
to get:
type Account struct
Id
UserId
Name
Address
City
State
CountryId
}
The substitution removes all non-white-space characters at the end of the line.
You can use C-V
and select the first column of all data type, then do $
to select until the end of the line, followed by x
or d
to delete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With