wincent/ferret

Exclude folders

Mte90 opened this issue · 10 comments

Mte90 commented

There is a way to exclude folders where ferret search?

Yes, depending on whether you are using ack, ag, rg etc, you can use various options, listed here:

let s:options = {
\ 'ack': [
\ '--ignore-ack-defaults',
\ '--ignore-case',
\ '--ignore-dir',
\ '--ignore-directory',
\ '--invert-match',
\ '--known-types',
\ '--literal',
\ '--no-recurse',
\ '--recurse',
\ '--sort-files',
\ '--type',
\ '--word-regexp',
\ '-1',
\ '-Q',
\ '-R',
\ '-i',
\ '-k',
\ '-r',
\ '-v',
\ '-w',
\ ],
\ 'ag': [
\ '--all-types',
\ '--all-text',
\ '--case-sensitive',
\ '--depth',
\ '--follow',
\ '--ignore',
\ '--ignore-case',
\ '--ignore-dir',
\ '--invert-match',
\ '--literal',
\ '--max-count',
\ '--skip-vcs-ignores',
\ '--unrestricted',
\ '--word-regexp',
\ '-Q',
\ '-U',
\ '-a',
\ '-i',
\ '-m',
\ '-s',
\ '-t',
\ '-u',
\ '-v',
\ '-w'
\ ],
\ 'rg': [
\ '--case-sensitive',
\ '--files-with-matches',
\ '--follow',
\ '--glob',
\ '--hidden',
\ '--ignore-case',
\ '--invert-match',
\ '--max-count',
\ '--maxdepth',
\ '--mmap',
\ '--no-ignore',
\ '--no-ignore-parent',
\ '--no-ignore-vcs',
\ '--no-mmap',
\ '--regexp',
\ '--smart-case',
\ '--text',
\ '--threads',
\ '--type',
\ '--type-not',
\ '--unrestricted',
\ '--word-regexp',
\ '-F',
\ '-L',
\ '-R',
\ '-T',
\ '-a',
\ '-e',
\ '-g',
\ '-i',
\ '-j',
\ '-m',
\ '-s',
\ '-t',
\ '-u',
\ '-v',
\ '-w'
\ ]
\ }

For example, --ignore-dir for ack, --ignore for ag etc.

Autocompletion is available for these when using :Ack and the other commands.

Mte90 commented

Cool, I searched for the term exclude instead ignore and missed that.
In the doc as I can see is not explained to configure them as global.
As example I want that hide stuff in the vendor folder but I don't want to write always the parameter.

@Mte90: since 09290a2 there is a way to configure default options to be passed to the search executable. For the time being, you can set the options once, globally, at start-up time. If you had a need to set it on a per-directory or per-project basis (for example, via an autocmd), we would need to make some changes to make that possible.

@wincent - I am using Ack, and wish to exclude the tags file in the base of all of my projects.

Currently when I search I get:

with_tags

My vimrc is basically:

    " search inside files using ripgrep. This plugin provides an Ack command.
    Plug 'wincent/ferret'
    let g:FerretHlsearch=0
    " search with ack for word under cursor
    nmap <leader>A <Plug>(FerretAckWord)
    " search & replace word based on previous search term with Ack
    nmap <leader>p <Plug>(FerretAcks)

I am unclear how to exclude by filename as per your helpful suggestions above. Would you please mind adding a one liner comment with a snippet that illustrates the solution. Thanks for this awesome plugin.

I tried:

    let g:FerretExecutableArguments = {
    \   'ack': '--ignore-file=tags'
    \ }

But unfortunately it didn't work, the tags results were still present in the quickfix window.

Ok, I solved this ON THE COMMAND LINE by creating a ~/.ackrc file, and adding:

--ignore-file=is:tags

In case anyone interested, I used this SOF answer and this template ackrc file.

The commit highlighted above by wincent was also helpful in case just wishing to do this locally.

Spoke too soon. This only works off the command line with ack. Inside VIM using this plugin, the tags file is still being searched. Also:

    let g:FerretExecutableArguments = {
    \   'ack': '--ignore-file=is:tags'
    \ }

Does NOT work. Please help!

Final comment. My apologies on this one. Am using ag (silver searcher) under the covers despite the :Ack command (as per the README). If I simply create a .ignore file, or else append tags to an existing .gitignore file then it suppresses the tags from appearing in search results.

This one was down to enduser error. Out.

@kinowarrior: yeah, adding it to the .gitignore is probably the easiest. I am not sure what the current status is with .ignore vs .agignore — it might be version and platform dependent, by the looks of issues like this one.

If anyone else is wondering why they can't ignore files when using ag it appears to be caused by this