I want to delete any lines that either match ^>$ or >\s

I have something like this, but this doesn't work:nnoremap dq :.,$g/^>[\s$]/d<CR>

Here's a small sample where it should delete the first 3 lines but not the last two (if we are currently at the top line of course):

> delete up to here


1 Answer 1


one way would be to use \| to specify two patterns: %g/^>$\|^>\s/d

  • 3
    Or :global/^>\($|\s\)/delete (note that :% is the default for :global)
    – D. Ben Knoble
    Aug 15, 2022 at 18:07
  • extremely weird, but it seems to me, that if I type it in manually it works, if I put it in an nmap it complains that Pattern not found: ^>$|^>\s (for @D.BenKnoble's variant as well, but with of course a slightly different pattern)
    – fbence
    Aug 15, 2022 at 21:07
  • 1
    @fbence in a mapping, \| is used to escape a | that would other end the map command start a new one (also written <bar>). So you can write :nnoremap ??? :global/^>\($\<bar>\s\)/delete<CR> or use \v with :nnoremap ??? :global/\v^>($<bar>\s)/delete<CR>. If you put it in a function and call the function from a mapping, you won't have this trouble.
    – D. Ben Knoble
    Aug 16, 2022 at 13:14
  • ah, ok, thanks!
    – fbence
    Aug 16, 2022 at 14:51

Your Answer

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

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