0

I have a very large table covering many pages in a document. The same footnote appears under the table on every page and I want to strip the entire document of these lines so I'm left only with the table. Imagine there are 3 footnotes like this:

This is a footnote
Another footnote
Yet another footnote

It seems I can delete the first footnote with :g/^T/d, and delete the 2nd with :g/^A/d, etc. But is there some way to tell vim to delete any line starting with T or A or Y in a single command?

It might seem unwise to run the command above over the entire document but the table is full of numbers and I know there are no other lines beginning with a letter aside from those in the footnote.

I checked the vim book by Robbins, Hannab & Lamb and couldnt see that it was possible. Can I assume an experienced vim user would simply type : and then use the arrow keys to recall the previous command and change the one letter, and repeat this for the number of lines in the footnote?

1
  • To answer the last question, I highly doubt an experienced vim user would use :<up> to change a single letter for every single footnote line :) In fact, if you know they all have a format like 1. , you can do something like :global/^\d\. /delete
    – D. Ben Knoble
    May 16, 2022 at 16:20

2 Answers 2

1

I think I found the answer, p75 Robbins, Hannab & Lamb: [] means "match any one of the characters enclosed between brackets."

So I would do:

:g/^[TAY]/d
1

More generally, see :help {pattern}. For more complex patterns, you might want alternations (/^\(T\|A\|Y\)/) or concats.

1
  • thanks! i have some vim reading to do :)
    – neverdimed
    May 16, 2022 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.