2

To find errors in a latex document, I open vim on the .log file. Then I type manually

/^l\.\|[Ee]rr\|[Ww]ar followed by RETURN

This extended regular expression works well. It matches a line starting with ell followed by a fullstop (period) OR the word "error", possibly capitalized OR the word "warning", possibly capitalized.

I would like to put this command into my .vimrc with the line

:map % "what should I put here?"

I made various attempts, including doubling some of the backslashes, but couldn't get it to work. I want vim to look for a match for my extended regular expression when I type "%"

1
  • Take a look at the quickfix functionality, as well as makeprg and errfmt
    – D. Ben Knoble
    Apr 16, 2019 at 12:32

2 Answers 2

1

your mapping should be:

nnoremap % /^l\.\|[Ee]rr\|[Ww]ar<CR>

<CR> is a carriage return, your "enter key".

And nnoremap instead of map so that it is done only in Normal mode and does not recursively calls mappings if anything in your mapping is itself a mapping.

0

I found that I needed to double the backslashes before the pipe \| However, vim decreed that I should NOT use a double backslash before the fullstop/period. So, what worked was

nnoremap % /^l\.\\|[Ee]rr\\|[Ww]ar<CR>

It also works fine with "map" instead of "nnoremap", though it's obviously safer to do the right thing.

Quite tricky! Note that, when entering the search sequence directly from the keyboard, one must not double any of the backslashes.

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.