Using multiple templates in Vimgrep when mapping keys

In my vimrc, I had a mapping to find the entire line with TODO in them and put them in the quickfix window:

nnoremap <leader>f :vimgrep /TODO/j % \| :cw<CR> 

Now I want to add an alternative FIXME template in the same way. So I tried

  nnoremap <leader>f :vimgrep /TODO\|FIXME/j % \| :cw<CR> 

and

 nnoremap <leader>f :vimgrep /TODO<bar>FIXME/j % \| :cw<CR> 

but do not return any results.

  vimgrep /TODO|FIXME/j % 

works at the prompt: when entering manually. So far I have been working on this:

 function! FindFixme() vimgrep /TODO\|FIXME/j % cw endfunction nnoremap <leader>f :call FindFixme()<CR> 

But I don’t quite understand why I can’t get it to work as one map team.

Thanks.

+5
source share
1 answer

Alternate Regular Element \| and you really need to avoid | so that he does not complete the matching command. Taken together, you will need two backslashes: one for escaping and one for saving an element:

 nnoremap <leader>f :vimgrep /TODO\\|FIXME/j % \| :cw<CR> 

But I would prefer the notation <Bar> , perhaps even in combination with <Bslash> :

 nnoremap <leader>f :vimgrep /TODO<Bslash><Bar>FIXME/j % <Bar> :cw<CR> 

You can also shorten this to:

 nnoremap <leader>f :vimgrep /TODO<Bslash><Bar>FIXME/j %<Bar>cw<CR> 
+9
source

Source: https://habr.com/ru/post/1236838/


All Articles