I am using the helm-projectile setup from prelude and it has been a huge improvement to my workflow. The only remaining issue are auto-generated files (e.g. generated by CMake) which show up during helm-grep and similar operations.

Question: is there a way to exclude files in the projects folder tree from Projectile?

6 Answers 6


Looking at projectile it seems to offer four customizations for ignoring files/directories globally. I am listing each of them below, with their documentation


A list of files globally ignored by projectile.


A list of directories globally ignored by projectile.


A list of file suffixes globally ignored by projectile.


A list of regular expressions for major modes ignored by projectile.

If a buffer is using a given major mode, projectile will ignore it for functions working with buffers.

Please note that these are global options so for example a directory in projectile-globally-ignored-directories will be ignored irrespective of the project you are working with. To ignore a file/directory for a particular project you can add a .projectile file to the project's root and add the paths to ignore prefixed with - to it like following


See the documentation of projectile-parse-dirconfig-file (or projectile's docs) for more info

Parse project ignore file and return directories to ignore and keep.

The return value will be a cons, the car being the list of directories to keep, and the cdr being the list of files or directories to ignore.

Strings starting with + will be added to the list of directories to keep, and strings starting with - will be added to the list of directories to ignore. For backward compatibility, without a prefix the string will be assumed to be an ignore string.

  • 4
    I'm unable to get projectile-globally-ignored-file-suffixes to work as (I think) it is intended. Should this contain just the suffix (i.e. "o" for object files), a file glob (i.e. "*.o") or something else? Frankly I've tried every combo I can think of and it hasn't worked.
    – Bklyn
    Commented Nov 20, 2017 at 15:17
  • I am using Scala with ensime, and projectile already defines .ensime_cache as globally ignored. However C-c p h brings up helm-projectile and shows all the .ensime_cache files. Any ideas?
    – Arne
    Commented Mar 28, 2019 at 12:48
  • 2
    @Bklyn: It is a list of just the suffix (e.g. (setq projectile-globally-ignored-file-suffixes '("o"))). You need to purge the cache after changing the setting though (M-x projectile-invalidate-cache).
    – shouya
    Commented Mar 31, 2020 at 4:53
  • @ShouYa (setq projectile-globally-ignored-file-suffixes '("S" "elf" "o" "d" "tex")) This doesn't work for me.
    – Swedgin
    Commented Oct 15, 2020 at 11:35
  • 2
    Not working if you use the indexing method alien, default for linux and mac. See an alternative solution from me below.
    – oracleyue
    Commented Mar 5, 2021 at 7:35

Yes, in your .projectile file, on each line specify similar to: each line looks like:

- /path/to/somefile

Each line contains one file path.

See the official documentation on ignoring files


Another solution would be to use ag(the_silver_searcher) or rg (ripgrep) to generate project files. Here's how you can do it with rg:

(setq projectile-enable-caching t)

;;; Default rg arguments
  ;; https://github.com/BurntSushi/ripgrep
  (when (executable-find "rg")
      (defconst modi/rg-arguments
        `("--line-number"                     ; line numbers
          "--follow"                          ; follow symlinks
          "--mmap")                           ; apply memory map optimization when possible
        "Default rg arguments used in the functions in `projectile' package.")

      (defun modi/advice-projectile-use-rg ()
        "Always use `rg' for getting a list of all files in the project."
        (mapconcat 'identity
                   (append '("\\rg") ; used unaliased version of `rg': \rg
                           '("--null" ; output null separated results,
                             "--files")) ; get file names matching the regex '' (all files)
                   " "))

      (advice-add 'projectile-get-ext-command :override #'modi/advice-projectile-use-rg)))

In your project directory, specify the files you want to ignore in .gitignore and you're good to go :)

Code is from kaushalmodi's emacs config.


Check if the variable projectile-indexing-method is set to alien. If that's the case Projectile will ignore ignores/unignores/sorting provided in Projectile config:

The alien indexing method optimizes to the limit the speed of the hybrid indexing method. This means that Projectile will not do any processing of the files returned by the external commands and you’re going to get the maximum performance possible. This behaviour makes a lot of sense for most people, as they’d typically be putting ignores in their VCS config and won’t care about any additional ignores/unignores/sorting that Projectile might also provide.

To solve it change this variable to native or hybrid.

  • 1
    More: If native is slow for you, the alternative to get both is to add ignore files and folders in your "projectile-generic-command". I use "rg" (ripgrep) for ultra speed. e.g., add to your default "rg" setup the additional arguments "--glob '!YourFolder1' --glob '!YourFolder2' --ignore-file YourFileToListFilesThatIgnoredGlobally"
    – oracleyue
    Commented Mar 5, 2021 at 7:00

search that respects ignored dirs/files:

  1. install ack (An alternative to grep. I install via homebrew.)

  2. put --ignore-case in your ~.ackrc file (assuming you want to ignore case)

  3. bind helm-projectile-ack to a key. I do this in my emacs init via:

(use-package helm
  :bind (...
         ("C-c p s a" . helm-projectile-ack)
  1. create a .projectile file. E.g.,


C-c p s a     ;; search that respects .projectile ignore


C-c s p g     ;; search everything

A new solution with no speed compromise of projectile

Since projetile-indexing-method is default set to alien, both projectile-globally-ignored-directories and projectile-globally-ignored-files will not be used. However, choosing native indexing method compromises speed performance considerably, especially for large projects.

Suppose we prefer alien for best performance, there is a way to get both satisfied. The idea is to set projectile-generic-command that is used for alien type indexing. Assume we use ripgrep (terminal command rg), we can add arguments to rg to ignore folders/files as you prefer,

  • ignoring folder by option --glob with folders read from projectile-globally-ignored-directories that you set;

  • ignoring files by option --ignore-file. However, this option specifies a file that lists all files to be ignored. The easy way is to create a global file (e.g., in ~/.emacs.d/) and list there all files that you like to put to projectile-globally-ignored-files. For example, we set a file name ~/.emacs.d/rg_ignore.

The whole setup as an example is given below:

  ;; Due to "alien" indexing method, globally ignore folders/files by
  ;; re-defining "rg" args
  (mapc (lambda (item)
          (add-to-list 'projectile-globally-ignored-directories item))
        '("Backup" "backup" "auto" "archived"))
  ;; files to be ignored should be listed in "~/.emacs.d/rg_ignore"

  ;; Use the faster searcher to handle project files: ripgrep "rg"
  (when (and (not (executable-find "fd"))
             (executable-find "rg"))
    (setq projectile-generic-command
          (let ((rg-cmd ""))
            (dolist (dir projectile-globally-ignored-directories)
              (setq rg-cmd (format "%s --glob '!%s'" rg-cmd dir)))
            (setq rg-ignorefile
                  (concat "--ignore-file" " "
                          (expand-file-name "rg_ignore" user-emacs-directory)))
            (concat "rg -0 --files --color=never --hidden" rg-cmd " " rg-ignorefile))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.