Mert Nuhoglu
Mert Nuhoglu

Reputation: 10143

Delete all lines upto some regex match

I want to delete everything from start of the document upto some regex match, such as _tmm. I wrote the following custom command:

command! FilterTmm exe 'g/^_tmm\\>/,/^$/mo$' | norm /_tmm<CR> | :0,-1 d

This doesn't work as expected. But when I execute these commands directly using the command line, they work.

Do you have any alternative suggestions to accomplish this job using custom commands?

Upvotes: 1

Views: 99

Answers (1)

Kent
Kent

Reputation: 195229

It seems that you want to remove from beginning to the line above the matched line.

/pattern could have offset option. like /pattern/{offset}, :h / for detail, for your needs, you could do (no matter where your cursor is):

ggd/_tmm/-1<cr>

EDIT

I read your question twice, it seems that you want to do it in a single command line.

Your script has problem, normal doesn't support |, that is, it must be the last command.

try this line, if it works for you:

exe 'norm gg'|/_tmm/-1|0,.d

Upvotes: 1

Related Questions