Shougo / unite.vim

:dragon: Unite and create user interfaces
http://www.vim.org/scripts/script.php?script_id=3396
Other
2.85k stars 223 forks source link

Unite.vim does not work with Target: . when greping through grep, ack or ag #1099

Closed mrt181 closed 8 years ago

mrt181 commented 8 years ago

Unite grep does not work with the

Target: .
set nocompatible

set runtimepath+=~/.vim/bundle/vimproc.vim/
set runtimepath+=~/.vim/bundle/unite.vim/

call unite#filters#matcher_default#use(['matcher_fuzzy'])
call unite#filters#sorter_default#use(['sorter_rank'])
let g:unite_split_rule = 'botright'
let g:unite_enable_ignore_case = 1
let g:unite_enable_smart_case = 1
let g:unite_enable_start_insert = 1
let g:unite_source_hisory_yank_enable = 1
if executable('ag')
  let g:unite_source_grep_command = 'ag'
  let g:unite_source_grep_default_opts =
    \ '-i --vimgrep --smart-case --nocolor --nogroup --hidden ' .
    \ '--ignore ''.svn'' --ignore ''.git'' ''.cabal-sandbox'' --ignore ''.stack-work'''
  let g:unite_source_grep_recursive_opt = ''
  let g:unite_source_rec_async_command =
    \ 'ag --follow --nocolor --nogroup --hidden -g ""'
elseif executable('ack')
  let g:unite_source_grep_command = 'ack'
  let g:unite_source_grep_default_opts =
    \ '-i --smart-case --nogroup --nocolor --ignore-dir=''.git, .cabal-sandbox, .stack-work'''
  let g:unite_source_grep_recursive_opt = ''
  let g:unite_source_rec_async_command =
    \ 'ack -f --nofilter --nogroup --nocolor'
endif

call unite#custom#source('file_rec/async,file_rec/git', 'ignore_globs', [])
$ pwd
/home/mrt181
$ touch .vim/test.txt
$ echo Hello\ unite.vim! > .vim/test.txt
$ ack -i --smart-case --nogroup --nocolor --ignore-dir='.git, .cabal-sandbox, .stack-work' Hello\ unite.vim!
.vim/test.txt:1:Hello unite.vim!
$ ag -i --vimgrep --smart-case --nogroup --nocolor --ignore='.git' --ignore='.cabal-sandbox' --ignore='.stack-work' Hello\ unite.vim!
.vim/test.txt:1:1:Hello unite.vim!

it works and gives me the searched pattern in the test file.

But when I do this from inside vim

$ pwd
/home/mrt181
$ vim
:Unite grep
Target: .
Pattern: hello\ unite.vim!

I get this message with ack

[grep] Pattern: hello\ unite.vim!
[unite.vim] [grep] ack: : No such file or directory
Press ENTER or type command to continue

and this with ag

[grep] Pattern: hello\ unite.vim!
[unite.vim] [grep] ERR: Error stat()ing: hello\ unite.vim!
[unite.vim] [grep] ERR: Error opening directory hello\ unite.vim!: No such file or directory
Press ENTER or type command to continue

When I disable ag and ack in .vimrc and do this from inside vim

$ pwd
/home/mrt181
$ vim
:Unite grep
Target: .
Pattern: hello\ unite.vim!

I get this message with grep

[grep] Pattern: hello\ unite.vim!
[unite.vim] [grep] /usr/bin/grep: : No such file or directory
Press ENTER or type command to continue

BUT when I do this

$ pwd
/home/mrt181
$ vim
:Unite grep
Target: /home/mrt181
Pattern: hello\ unite.vim!

I get this message with grep and ack and end up in INSERT mode in the unite window

./.vim/test.txt 1 Hello unite.vim!

ag still gives me this

[grep] Pattern: hello\ unite.vim!
[unite.vim] [grep] ERR: Error stat()ing: hello\ unite.vim!
[unite.vim] [grep] ERR: Error opening directory hello\ unite.vim!: No such file or directory
Press ENTER or type command to continue

So it looks like that unite.vim is not expanding the target . and this causes issues.

mrt181 commented 8 years ago

These commands all work from cygwin

mrt181@windowsmachine ~
$ ack -i --smart-case --nogroup --nocolor --ignore-dir='.git, .cabal-sandbox, .stack-work' Hello\ unite.vim!
.vim.bak/test.txt:1:Hello unite.vim!

mrt181@windowsmachine ~
$ ack -i --smart-case --nogroup --nocolor --ignore-dir='.git, .cabal-sandbox, .stack-work' Hello\ unite.vim! .
.vim.bak/test.txt:1:Hello unite.vim!

mrt181@windowsmachine ~
$ ack -i --smart-case --nogroup --nocolor --ignore-dir='.git, .cabal-sandbox, .stack-work' Hello\ unite.vim! .vim.bak/
.vim.bak/test.txt:1:Hello unite.vim!

But with unite.vim it only works when I give a target that is not

.

E.g.

:Unite grep
Target: .
Pattern: hello\ unite.vim
[unite.vim] [grep] ack: : No such file or directory
:Unite grep
Target: .vim.bak/
Pattern: hello\ unite.vim
.vim.bak/test/txt 1 Hello unite.vim!

I have already thrown away my vim setup and reinstalled everything but the problem does not go away

mrt181 commented 8 years ago

These commands all work from terminal

mrt181@ubuntumachine ~
$ ag -i --smart-case --nogroup --nocolor --hidden --ignore '.git' --ignore '.cabal-sandbox' --ignore '.stack-work' hello\ unite.vim                                                                                                                                                                                          
.vim.bak/test.txt:1:Hello unite.vim!

mrt181@ubuntumachine ~
$ ag -i --smart-case --nogroup --nocolor --hidden --ignore '.git' --ignore '.cabal-sandbox' --ignore '.stack-work' hello\ unite.vim .
.vim.bak/test.txt:1:Hello unite.vim!

mrt181@ubuntumachine ~
$ ag -i --smart-case --nogroup --nocolor --hidden --ignore '.git' --ignore '.cabal-sandbox' --ignore '.stack-work' hello\ unite.vim .vim.bak/
.vim.bak/test.txt:1:Hello unite.vim!

But with unite.vim it does not regardless of the taget I provide E.g.

:Unite grep
Target: .
Pattern: hello\ unite.vim
[unite.vim] [grep] ERR: Error stat()ing: hello\ unite.vim
[unite.vim] [grep] ERR: Error opening directory hello\ unite.vim: No such file or directory
:Unite grep
Target: .vim.bak/
Pattern: hello\ unite.vim
[unite.vim] [grep] ERR: Error stat()ing: hello\ unite.vim
[unite.vim] [grep] ERR: Error opening directory hello\ unite.vim: No such file or directory

I have already thrown away my vim setup and reinstalled everything but the problem does not go away

Shougo commented 8 years ago

Unfortunately, I cannot reproduce the problem. @mrt181 Please execute <C-a> in the unite buffer normal mode. It is unite executed command line. And you can execute it from the cmdline.

   let g:unite_source_grep_default_opts =
    \ '-i --vimgrep --smart-case --nocolor --nogroup --hidden ' .
    \ '--ignore ''.svn'' --ignore ''.git'' ''.cabal-sandbox'' --ignore ''.stack-work'''

It must be:

  let g:unite_source_grep_default_opts =
    \ '-i --vimgrep --smart-case --nocolor --nogroup --hidden ' .
    \ '--ignore ''.svn'' --ignore ''.git'' --ignore ''.cabal-sandbox'' --ignore ''.stack-work'''
mrt181 commented 8 years ago

Ok, I see that the executed commandline does not contain the specified target.

unite vim

mrt181 commented 8 years ago

Ok, i was able to fix the problem.

I had to errors in the unite config

This missing --ignore before ''.cabal-sandbox'' when using ag Wrong dir list for --ignore-dir when using ack

The errors in unite were not helpful and the wrong ack config did not produce an error on the commandline.

Fixed options

  let g:unite_source_grep_default_opts =
    \ '-i --vimgrep --smart-case --nocolor --nogroup --hidden ' .
    \ '--ignore ''.svn'' --ignore ''.git'' --ignore ''.cabal-sandbox'' --ignore ''.stack-work'''
  let g:unite_source_grep_default_opts =
    \ '-i --smart-case --nogroup --nocolor --ignore-dir={.git, .cabal-sandbox, .stack-work}'
Shougo commented 8 years ago

OK. But I cannot improve it...

mrt181 commented 8 years ago

You don't need to, it was my error. Thank you for your help and all your awesome plugins