Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete all lines that match a pattern asking permission in vi

Tags:

vim

vi

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

like image 706
steT Avatar asked Sep 28 '22 09:09

steT


1 Answers

Only the :substitute command has the confirm 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
like image 188
Ingo Karkat Avatar answered Oct 13 '22 06:10

Ingo Karkat