Shougo / unite.vim

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

How to use vimgrep with Unite #315

Closed petobens closed 10 years ago

petobens commented 11 years ago

The following command :Unite vimgrep:%:\CTODO:\|FIXME:\|NOTE: only does "vimgrep /CTODO/j %" . How should I write my vimgprep command in Unite in order to matchcase and search for todos, fixmes and notes? Thanks in advance

petobens commented 11 years ago

I ended up using "ag". Thanks anyway.

UncleBill commented 11 years ago

ag is faster

petobens commented 11 years ago

Yes, much faster. There is however one problem: I'm using windows and the unite buffer displays "^M" (carriage returns) after running: nnoremap <silent><leader>ut :Unite grep:%::TODO\:\|FIXME\:\|NOTE\:<CR>. I know I can delete those characters with a mapping that performs the following substitution: %s/\r//g. I was wondering if there was some way of telling Unite not to show those characters? I tried setting set ffs = unix,dos but the "^M" still appears at end of lines.

petobens commented 11 years ago

Another question. With "ag", can I use the async flag when searching for files in Windows?. If I set nnoremap <silent><Leader>uf :Unite -silent -auto-resize file_rec/async<CR> I get an empty buffer. Am I doing something wrong?

Shougo commented 11 years ago

way of telling Unite not to show those characters? I tried setting set ffs = unix,dos but the "^M" still appears at end of lines.

Another question. With "ag", can I use the async flag when searching for files in Windows?

Sorry, I have not "ag" binary in Windows. So I cannot fix it.

Shougo commented 11 years ago

The following command :Unite vimgrep:%:\CTODO:|FIXME:|NOTE: only does "vimgrep /CTODO/j %" . How should I write my vimgprep command in Unite in order to matchcase and search for todos, fixmes and notes?

You must escape "\" and ":".

:Unite vimgrep:%:\\CTODO\:\\|FIXME\:\\|NOTE\:

UncleBill commented 11 years ago

Sorry, I have not "ag" binary in Windows. So I cannot fix it.

Maybe trimming ( like trimRight in js ) the lines could fix it.

petobens commented 11 years ago

Okay, until there is a fix I will be using:

nnoremap <silent> <leader>ut :Unite -toggle -auto-resize -auto-highlight
            \ vimgrep:%:\\CTODO\:\\<bar>FIXME\:\\<bar>NOTE\:<CR>
Shougo commented 11 years ago

Okay, until there is a fix I will be using:

To build ag in Windows is too difficult. So I can't fix it.

Maybe trimming ( like trimRight in js ) the lines could fix it.

No. Trimming is implemented. But it is not works. So I must try ag binary in Windows. But I cannot build it.

petobens commented 11 years ago

I got it from here

Shougo commented 11 years ago

Thanks. I will try it.

Shougo commented 11 years ago

I fixed the problem. Please update vimproc and unite.vim.

And you must use following settings to use ag.

    let g:unite_source_grep_command = 'ag'
    let g:unite_source_grep_default_opts =
          \ '--line-numbers --nocolor --nogroup --hidden --ignore ' .
          \  '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
    let g:unite_source_grep_recursive_opt = ''
UncleBill commented 11 years ago

By default, ag ignores VCS folders

2013/7/30 Shougo notifications@github.com

I fixed the problem. Please update vimproc and unite.vim.

And you must use following settings to use ag.

let g:unite_source_grep_command = 'ag'
let g:unite_source_grep_default_opts =
      \ '--line-numbers --nocolor --nogroup --hidden --ignore ' .
      \  '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
let g:unite_source_grep_recursive_opt = ''

— Reply to this email directly or view it on GitHubhttps://github.com/Shougo/unite.vim/issues/315#issuecomment-21784948 .

Shougo commented 11 years ago

By default, ag ignores VCS folders

Yes. But it ignores other hidden files.

petobens commented 11 years ago

Thanks, after updating and setting set fileformat=unix in my vimrc file the carriage returns are not shown anymore and I can use file_rec/async source in Windows! There is however one problem, when I grep my vimrc to find todos with the map:

nnoremap <silent><leader>ug :Unite -silent -auto-resize -auto-highlight 
            \ grep:%::TODO\:\|FIXME\:\|NOTE\:<CR>

I get a warning saying

unite:jump_list: Invalid action__line format.

Can I ignore it or is it a problem?

petobens commented 11 years ago

I think the problem is due to the auto-highlight flag? I can't use that flag while grepping?

Shougo commented 11 years ago

I get a warning saying unite:jump_list: Invalid action__line format. Can I ignore it or is it a problem?

No. I think your unite-grep settings are wrong.

petobens commented 11 years ago

I think there is still a problem with the carriage returns. If I grep the same file for instance to findo todos with

nnoremap <silent><leader>ug :Unite -silent -auto-resize grep:%::TODO\:\|FIXME\:\|NOTE\:<CR>

then no carriage returns appear but if just call :Unite grep and grep a different directory than that of the current file the ^M characters still appears.

Shougo commented 11 years ago

You should create minimal .vimrc and sample text file without other plugins. If you show it, I will check it.

petobens commented 11 years ago

Minimal vimrc like this?:

set nocompatible
set runtimepath+=path/to/plugin
Shougo commented 11 years ago

Yes.

petobens commented 11 years ago

If I run gvim with this vimrc:

set nocompatible
let mapleader = ","
set runtimepath+=$HOME\vimfiles\bundle\unite
set runtimepath+=$HOME\vimfiles\bundle\vimproc
set encoding=utf-8
set fileformat=unix
set fileformats=unix,dos
if executable('ag')
    let g:unite_source_grep_command = 'ag'
    let g:unite_source_grep_default_opts =
                \ '--smart-case --line-numbers --nocolor --nogroup'
    let g:unite_source_grep_recursive_opt = ''
endif
nnoremap <silent> <Leader>ag :Unite -silent -auto-resize
        \ -buffer-name=ag grep<CR>

I can still reproduce the problem as you can see in the image below. agproblem2

Shougo commented 11 years ago

OK. I will check it.

Shougo commented 11 years ago

I fixed the problem. Please update vimproc.

petobens commented 11 years ago

Thank you so much!! :-)

ReneFroger commented 10 years ago

I get the warning "unite:jump_list: Invalid action__line format." too.

You said earlier in this thread (august 2013) that the unite-grep settings are wrong. That is odd, because I copied the grep settings from the example from your excellent documentation.

I created a minimal Vimrc, without any plugins. The problem is reproducable. I use Gvim under Windows7.

My mnimal Vimrc:

set nocompatible                         
execute pathogen#infect()
syntax on
filetype plugin indent on

"Unite    {
let g:unite_source_rec_async_command =
            \ 'ag --follow --nocolor --nogroup --hidden -g ""'
let g:unite_source_file_async_command =
            \ 'ag --follow --nocolor --nogroup --hidden -g ""'
        call unite#filters#matcher_default#use(['matcher_fuzzy'])
        call unite#filters#sorter_default#use(['sorter_rank'])
        call unite#custom#profile('default', 'context', {
        \   'start_insert': 1,
        \   'winheight': 50,
        \   'direction': 'botright',
        \   'prompt': '» ',
        \ })
        call unite#custom#source('file,file/new,file_mru,buffer,file_rec',
       \ 'matchers', 'matcher_fuzzy')
        let g:unite_data_directory='~/.vim/.cache/unite'
        let g:unite_source_history_yank_enable=1
        if executable('ag')
            let g:unite_source_grep_command='ag'
            "let g:unite_source_grep_default_opts='--nocolor --nogroup -S -C4'
            let g:unite_source_grep_default_opts='--nocolor --nogroup -S'
            let g:unite_source_grep_recursive_opt=''
        endif

let g:agprg="C:/Dropbox/Vim/vim74/ag.exe --column --smart-case"

I use the following plugins:

Unite Unite Neomru https://github.com/rking/ag.vim

I cannot use Unite grep after entering my search word, I get blocked by the message

unite:jump_list: Invalid action__line format.
Shougo commented 10 years ago

OK. Please upload your grepped files. I cannot reproduce it.

And please upload reproduce ways(see issue template).

ReneFroger commented 10 years ago
Shougo commented 10 years ago

I think it is Windows environment issue. Can you test it in other environment?

And your .vimrc is not minimal. It should be more reduced. Please use set rtp+={plugin path} instead of pathogen.

Shougo commented 10 years ago

I get it. I reproduced. It is ag arguments issue.

Please use this:

let g:unite_source_grep_default_opts='--nocolor --nogroup -S'

You said earlier in this thread (august 2013) that the unite-grep settings are wrong. That is odd, because I copied the grep settings from the example from your excellent documentation.

No. It is in documentation arguments:

      " Use ag in unite grep source.
      let g:unite_source_grep_command = 'ag'
      let g:unite_source_grep_default_opts =
      \ '-i --line-numbers --nocolor --nogroup --hidden --ignore ' .
      \  '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
      let g:unite_source_grep_recursive_opt = ''
ReneFroger commented 10 years ago

I changed it to

let g:unite_source_grep_default_opts='--nocolor --nogroup -S'

Your solution is not working, I still get the same message. Then I tried another solution.

let g:unite_source_grep_default_opts='-i --nocolor --nogroup -S'

Worked for me, oddly.