bling / fzf.el

A front-end for fzf
GNU General Public License v3.0
360 stars 50 forks source link

fzf.el MELPA

An Emacs front-end for fzf.

demo

installation

fzf.el is available on MELPA.

Below is an illustrative use-package configuration of fzf.el showing all available customizations and their default values.

Note: This package does not set default keybindings.

(use-package fzf
  :bind
    ;; Don't forget to set keybinds!
  :config
  (setq fzf/args "-x --color bw --print-query --margin=1,0 --no-hscroll"
        fzf/executable "fzf"
        fzf/git-grep-args "-i --line-number %s"
        ;; command used for `fzf-grep-*` functions
        ;; example usage for ripgrep:
        ;; fzf/grep-command "rg --no-heading -nH"
        fzf/grep-command "grep -nrH"
        ;; If nil, the fzf buffer will appear at the top of the window
        fzf/position-bottom t
        fzf/window-height 15))

usage

fzf.el comes with a number of useful commands:

Using FZF_DEFAULT_COMMAND:

Searching for files:

Project-aware search:

Grep:

Note: fzf-grep-*-with-narrowing functions launch an interactive fzf/grep-command instead of using fuzzy filtering. See the fzf advanced documentation for more details.

  • M-x fzf-grep
  • M-x fzf-grep-dwim
  • M-x fzf-grep-in-dir
  • M-x fzf-grep-with-narrowing
  • M-x fzf-grep-dwim-with-narrowing
  • M-x fzf-grep-in-dir-with-narrowing

Using input from Emacs:

define custom functions

fzf.el exposes functions to let you interface with fzf however you'd like:

Using these functions, it's easy to define your own commands that use fzf:

(defun fzf-example ()
  (fzf-with-entries
   (list "a" "b" "c")
   'print))

Or more exciting:

(defun fzf-find-file (&optional directory)
  (interactive)
  (let ((d (fzf/resolve-directory directory)))
    (fzf
    (lambda (x)
        (let ((f (expand-file-name x d)))
        (when (file-exists-p f)
            (find-file f))))
    d)))

license

GPL3