dkprice / vim-easygrep

Fast and Easy Find and Replace Across Multiple Files
The Unlicense
325 stars 47 forks source link

Regex numbers are not working #15

Closed wikimatze closed 9 years ago

wikimatze commented 9 years ago

Hi,

I want to search after files containing strings like #L1767 as well as #L86. Running $ack-grep "#L\d{2,}" from the command line give me the expected result. I can even use this command with ack.vim plugin and got the same results. But running the regex in Vim with :Grep "#L\d{2,}" give me the following error:

[EasyGrep] Warning: No matches for '"\#L\d{4,}"'
[EasyGrep] Warning: File Pattern: * (+Recursive)
[EasyGrep] Warning: Directories: /home/wm/ownCloud/padrino/manuscript/chapters

So there is a problem with the quantifiers. I'm using the following vim settings:

let g:EasyGrepAllOptionsInExplorer=1 " don't show advanced greping options
let g:EasyGrepFilesToExclude="tags"  " not usable if I use ag for searching
let g:EasyGrepInvertWholeWord=0      " <Leader>vv matches word, and <Leader>vV matches whole word

let g:EasyGrepReplaceWindowMode=2      " autowriteall all changes during a search and replace session
let g:EasyGrepOptionPrefix='<leader>e' " shortcut to turn on and off certain grepoptions
let g:EasyGrepRecursive=1              " turn on recurse option for replacement
let g:EasyGrepCommand=1                " using system 'grepprg' instead of 'vimgrep

if executable('pt')
  set grepprg=pt
elseif executable('ag')
  set grepprg=ag
endif

I think you are missing an -e option when doing a regex search. Is there an easy solution for this problem because I want to use only your plugin and not another one.

Thanks for the plugin.

dkprice commented 9 years ago

Hi,

I think there are two problems here. I submitted a fix for the first; the second is related to escaping. Getting this right across all of the various tools that people would like to use has been annoying and often error-prone as you encountered here. If you sync my change and use this command it should work for you now:

:Grep \#L\d{2,}

The double-quotes around your token are an interesting problem. In EasyGrep I've actually taken care to preserve the argument (quotes and all) as it is passed through to calling :grep. When calling from a shell, the shell will actually strip your double-quotes before it is passed through to the executable. Whether or not EasyGrep should do the same is something that is certainly open for discussion.

wikimatze commented 9 years ago

I see, I will try it out. Yeah, using to many replacing tools is maybe too much without tests, so we should start writing them.