Basic setup
Note
Everything in this section assumes you've enabled projectile-mode
.
To add a project to Projectile's list of known projects, open a file
in the project. If you have a projects directory, you can tell
Projectile about all of the projects in it with the command M-x
projectile-discover-projects-in-directory
.
You can go one step further and set a list of folders which Projectile is automatically going to check for projects:
(setq projectile-project-search-path '("~/projects/" "~/work/"))
If you're going to use the default ido
completion it's
extremely highly recommended that you install the optional
flx-ido package, which provides a much
more powerful alternative to ido
's built-in flex
matching.
Interactive Commands
Here's a list of the interactive Emacs Lisp functions, provided by Projectile:
Keybinding | Description |
---|---|
C-c p f | Display a list of all files in the project. With a prefix argument it will clear the cache first. |
C-c p F | Display a list of all files in all known projects. |
C-c p g | Display a list of all files at point in the project. With a prefix argument it will clear the cache first. |
C-c p 4 f | Jump to a project's file using completion and show it in another window. |
C-c p 4 g | Jump to a project's file based on context at point and show it in another window. |
C-c p 5 f | Jump to a project's file using completion and show it in another frame. |
C-c p 5 g | Jump to a project's file based on context at point and show it in another frame. |
C-c p d | Display a list of all directories in the project. With a prefix argument it will clear the cache first. |
C-c p 4 d | Switch to a project directory and show it in another window. |
C-c p 5 d | Switch to a project directory and show it in another frame. |
C-c p T | Display a list of all test files(specs, features, etc) in the project. |
C-c p l | Display a list of all files in a directory (that's not necessarily a project) |
C-c p s g | Run grep on the files in the project. |
M-- C-c p s g | Run grep on projectile-grep-default-files in the project. |
C-c p v | Run vc-dir on the root directory of the project. |
C-c p V | Browse dirty version controlled projects. |
C-c p b | Display a list of all project buffers currently open. |
C-c p 4 b | Switch to a project buffer and show it in another window. |
C-c p 5 b | Switch to a project buffer and show it in another frame. |
C-c p 4 C-o | Display a project buffer in another window without selecting it. |
C-c p a | Switch between files with the same name but different extensions. |
C-c p 4 a | Switch between files with the same name but different extensions in other window. |
C-c p 5 a | Switch between files with the same name but different extensions in other frame. |
C-c p o | Runs multi-occur on all project buffers currently open. |
C-c p r | Runs interactive query-replace on all files in the projects. |
C-c p i | Invalidates the project cache (if existing). |
C-c p R | Regenerates the projects TAGS file. |
C-c p j | Find tag in project's TAGS file. |
C-c p k | Kills all project buffers. |
C-c p D | Opens the root of the project in dired . |
C-c p 4 D | Opens the root of the project in dired in another window. |
C-c p 5 D | Opens the root of the project in dired in another frame. |
C-c p e | Shows a list of recently visited project files. |
C-c p E | Opens the root dir-locals-file of the project. |
C-c p s s | Runs ag on the project. Requires the presence of ag.el . |
C-c p ! | Runs shell-command in the root directory of the project. |
C-c p & | Runs async-shell-command in the root directory of the project. |
C-c p C | Runs a standard configure command for your type of project. |
C-c p c | Runs a standard compilation command for your type of project. |
C-c p P | Runs a standard test command for your type of project. |
C-c p t | Toggle between an implementation file and its test file. |
C-c p 4 t | Jump to implementation or test file in other window. |
C-c p 5 t | Jump to implementation or test file in other frame. |
C-c p z | Adds the currently visited file to the cache. |
C-c p p | Display a list of known projects you can switch to. |
C-c p S | Save all project buffers. |
C-c p m | Run the commander (an interface to run commands with a single key). |
C-c p ESC | Switch to the most recently selected Projectile buffer. |
If you ever forget any of Projectile's keybindings just do a:
C-c p C-h
You can change the default keymap prefix C-c p
like this:
(setq projectile-keymap-prefix (kbd "C-c C-p"))
It is also possible to add additional commands to
projectile-command-map
referenced by the prefix key in
projectile-mode-map
. You can even add an alternative prefix for all
commands. Here's an example that adds super-p
as the extra prefix:
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
You can also bind the projectile-command-map
to any other map you'd
like (including the global keymap).
For some common commands you might want to take a little shortcut and
leverage the fairly unused Super
key (by default Command
on Mac
keyboards and Windows
on Win keyboards). Here's something you can
add to your Emacs config:
(define-key projectile-mode-map [?\s-d] 'projectile-find-dir)
(define-key projectile-mode-map [?\s-p] 'projectile-switch-project)
(define-key projectile-mode-map [?\s-f] 'projectile-find-file)
(define-key projectile-mode-map [?\s-g] 'projectile-grep)
Note that the Super
keybindings are not usable in Windows. Emacs
Prelude already adds those extra keybindings.
Ignoring files
If you'd like to instruct Projectile to ignore certain files in a
project, when indexing it you can do so in the .projectile
file by
adding each path to ignore, where the paths all are relative to the
root directory and start with a slash. Everything ignored should be
preceded with a -
sign. Alternatively, not having any prefix at all
also means to ignore the directory or file pattern that follows.
Here's an example for a typical Rails application:
-/log
-/tmp
-/vendor
-/public/uploads
This would ignore the folders only at the root of the project. Projectile also supports relative pathname ignores:
-tmp
-*.rb
-*.yml
-models
You can also ignore everything except certain subdirectories. This is useful when selecting the directories to keep is easier than selecting the directories to ignore, although you can do both. To select directories to keep, that means everything else will be ignored.
Example:
+/src/foo
+/tests/foo
Keep in mind that you can only include subdirectories, not file patterns.
If both directories to keep and ignore are specified, the directories to keep first apply, restricting what files are considered. The paths and patterns to ignore are then applied to that set.
Finally, you can override ignored files. This is especially useful when some files ignored by your VCS should be considered as part of your project by projectile:
!/src/foo
!*.yml
When a path is overridden, its contents are still subject to ignore patterns. To override those files as well, specify their full path with a bang prefix.