Hello I'm new with vi and i have a problem making vi ask me the permission to delete all line with a pattern. My file looks like this:
SEQRES 1 A 46 GLY SER GLU ALA ARG GLU CYS VAL ASN CYS GLY ALA THR
SEQRES 2 A 46 ALA THR PRO LEU TRP ARG ARG ASP ARG THR GLY HIS TYR
SEQRES 3 A 46 LEU CYS ASN ALA CYS GLY LEU TYR HIS LYS MET ASN GLY
SEQRES 4 A 46 GLN ASN ARG PRO LEU ILE ARG
I want to delete all the lines that contain the string 'GLY'
This is what i came up to:
:g/GLY/cd
but it's definitely wrong
Only the :substitute
command has the c
onfirm flag. However, if you use a regular expression that matches the entire line (including the trailing newline), you can use that to delete entire lines, with confirmation:
:%s/.*GLY.*\n//c
Alternatively, you could build your own confirmation into :global
; here's a simple one that you have to answer with either Enter or Esc:
:g/GLY/if confirm('Delete: ' . getline('.')) | delete _ | endif
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