Giter Site home page Giter Site logo

fzf.el's Introduction

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:

  • M-x fzf
  • M-x fzf-directory

Searching for files:

  • M-x fzf-find-file
  • M-x fzf-find-file-in-dir
  • M-x fzf-recentf

Project-aware search:

  • M-x fzf-git
  • M-x fzf-git-files
  • M-x fzf-git-grep
  • M-x fzf-hg
  • M-x fzf-projectile

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:

  • M-x fzf-switch-buffer

define custom functions

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

  • fzf-with-command (command action &optional directory as-filter initq): Run fzf on the output of a shell command.
    • command: The shell command whose output is passed to fzf.
    • action: A function that handles the result of fzf (e.g. open a file, switch to a buffer, etc.). This package ships with two default actions that can handle opening a file and opening a file at a specific line.
    • directory: Directory to execute fzf in.
    • as-filter: If non-nil, use command as the filter instead of fzf's fuzzy filtering. See fzf-grep-*-with-narrowing functions for example usages.
    • initq: If as-filter is non-nil, initq will be used as the value for the --query option. If as-filter is nil, this does nothing.
  • fzf-with-entries (entries action &optional directory): run fzf, passing in an elisp list and running the function action with the user's selected results.

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

fzf.el's People

Contributors

15cm avatar aeruder avatar agsdot avatar avli avatar bling avatar brandon-rhodes avatar dubiousdavid avatar fernando-jascovich avatar liuyincarl avatar pierre-rouleau avatar posita avatar rails-to-cosmos avatar rolag avatar romanodesouza avatar samclearman avatar sanel avatar tttuuu888 avatar vnckppl avatar xshyamx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fzf.el's Issues

fzf-git-files not visiting file after making selection

I'm using Emacs 27.1 and fzf 0.22.0 on macOS 10.15.7.

When I run fzf-git-files from graphical emacs, I can see a list of project files, but making a selection brings me back to the same buffer without visiting a new file.

However, when I use fzf-git-grep I am able to successfully visit a file after making a selection.

This doesn't appear to be an issue when I connect to emacs from Terminal.app.

I also tried installing emacs 26.3, but had the same problem.

Default directory

Hello,

I am trying to define a default directory where - always ! - execute fzf. I tried:

  • fzf/resolve-directory "/mydirectory" into the setq section (I use use-package) ; it works, but only once, after opening a file, fzf executes itself into the directory of this file
  • :init (setenv "FZF_DEFAULT_COMMAND" "fd . /mydirectory"), it works but... I can't open files! error: "FZF exited with code 0".
  • (defun test () (interactive) (fzf-with-command "fd . /mydirectory" #'fzf/action-find-file)) : same, "FZF exited with code 0" when I select a file to open it.

Note than I tried with another command, without specifying the directory :init (setenv "FZF_DEFAULT_COMMAND" "fd --type file -c always") and everything is working fine. The problem is not than the command is not recognized, but to open a file when a directory is specified...

Thanks to any clues...
PS: is someone knows how I could configure emacs/fzf.el to get an error log of this error...

Configurable window split position

I mean a defcustom controlling where it will appears(top or bottom for now).
top by default and with --reverse arg would be possible to display the * fzf * buffer on bottom.

What do you think, @bling ?

Cannot open .gitignore files

I'm sure this is due to some local nuance, but I cannot open .gitignore files through fzf. I see the file, but when I hit enter the buffer is not created. Anybody else having this issue?

dwim operations with grep -rnH do not work

I wonder if something broke recently or if that ever worked, but when one of the fzf-grep-dwim or fzf-grep-dwim-with-narrowing is used while fzf/grep-command uses grep (as opposed to rg) the operation does not work.

The reason it does not work is the grep command requires a file pattern to search otherwise it searches from its stdin. The 'dwim' commands provide a pattern that the command can append to fzf/grep-command but grep does not see any file pattern. So the grep operation fails. If we change fzf/grep-command to use rg (ripgrep) then it works because ripgrep recusively searches all files (except the hidden ones) by default.

So... I wonder... Did these dwim commands ever worked with 'grep -rnH' , or did I break something?

@bling, do you know?

fzf-with-entries no longer selects entries with slashes

When I run fzf-with-entries since commit 29c715b it no longer copies the items that contain slashes:

This works:

(progn
  (setq mylist '("abc" "def" "ghi"))
  (fzf-with-entries mylist
                    (lambda (x) (setq selected-entry x)))
  (message selected-entry)
  )

This does not:

(progn
  (setq mylist '("/abc" "/def" "/ghi"))
  (fzf-with-entries mylist
                    (lambda (x) (setq selected-entry x)))
  (message selected-entry)
  )

Output renders incorrectly in Emacs 25

I'm seeing the following rendering issue in Emacs 25:

screen shot 2016-10-22 at 8 11 26 pm

I vaguely remember this being a solved or worked-around problem, but can't seem to find where I saw discussion pertaining to it -- are there FZF arguments that mitigate the issue?

Map ESC for FZF window?

Hi,

Though the question has been asked:
#10

I still don't know how to map?

Besides, I use evil-mode, I found that if I press ESC in FZF window, it will turn to evil-normal-mode.

Could you give me more detail?
Thank you!

Customize colours

Thanks for this great plug-in!

I'm quite new to Emacs, maybe the question is not directly related to your plug-in. How can I change the default colours? I would like them to match the ones I put in my fzf configuration.

Unreadable output on latest update

fzf-broken

emacs --version
GNU Emacs 25.1.1
Copyright (C) 2016 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Running on macOS 10.10. This was working perfectly until I updated my emacs packages recently. Any clues on how to fix?

fzf sometimes fails with extra characters at the end of returned file name

Running on Emacs 26.3 with fzf 0.35.1.

I noticed that under some circumstances fzf or fzf-directory fail opening the file found and selected.

The error reported error in process sentinel: user-error: followed with a file name that either had trailing whitespaces or had extra characters like a '$' or other characters that seemed to be part of the file name.

Upon investigation I found that the target variable in fzf/after-term-handle-exit had either trailing whitespace or extra characters. I'm not sure if the problem is a fzf problem or an Emacs 26.3 problem getting the returned string properly.

In either case I solved the problem by adding protection code against these types of errors which do not impact performances:

  • string-trim target
  • check if target is an existing file and if not try removing characters from it's end and check again until a valid file is found.
  • If still can't find the valid file (which does not seem to happen anymore), issue a message describing the remaining problem for further investigation.

I will submit the bug fix once my previous PR (#83) is integrated.

stops working if I use with-editor to export $EDITOR with term-mode hook

The issue can be recreated with the following setting

(use-package with-editor
  :defer t
  :ensure t
  :hook ((term-mode . with-editor-export-editor)
	     (term-mode . with-editor-export-git-editor)
	 ))

Since such hooks to term-mode are very common it might be necessary to handle them correctly. I think it might be possible to run fzf after the term-mode-hook. I would appreciate any workaround.

Register names must be characters

At

fzf.el/fzf.el

Line 110 in 521d189

(window-configuration-to-register :fzf-windows)

Note documentation of window-configuration-to-register

(window-configuration-to-register REGISTER)

Probably introduced at or before Emacs version 19.20.

Store the window configuration of the selected frame in register REGISTER.
Use C-x r j to restore the configuration.
Argument is a character, naming the register.

See also emacs-evil/evil#1212

fzf launches but selecting an item doesn't cause the file to get opened

I'm using fzf and projectile. Launching the fzf buffer works fine and I can search for files but when I select a file by pressing enter, the fzf buffer closes but nothing else happens. Is there a way to debug the output from the fzf command line or otherwise figure out why it's not working?

Is this abandoned?

Hey @bling,

No worries either way, but wanted to see if this library is abandoned or not? I made a bunch of changes on my fork, as the issues section here seems quiet and the last commit was in 2018. I don't want to misrepresent the state of the library in my new README though.

Is there any way to get fzf search history

I would like to know if these is any way or function to get the fzf search history, because sometimes I forget the name of the file I opened with fzf a few minutes ago, if there is any function to get the history, I can bind it to a hotkey(such as Meta-up/Meta-dowm) to reopen the file.

Thanks.

Support for tags

Is it possible to do something similar to FzfTags in the vim integration?

suggest to add a `fzf-find-in-buffer` command

In the last few months,I fork the project and add a command fzf-find-in-buffer to fast find the pattern line and jump to it, the command works well and helped me read code faster, so I think maybe can add it to fzf.el.

image

image

the code can find in here. fa2306f

(defun fzf-with-command-and-args (command action &optional fzf-append-args directory)
  (interactive)
  (if command
      (let
          ((process-environment (cons (concat "FZF_DEFAULT_COMMAND=" command "") process-environment))
           (args (if fzf-append-args
                    (concat fzf/args " " fzf-append-args)
                    fzf/args)))
        (fzf/start directory action args))
    (fzf/start directory action)))

(defun fzf/action-goto-line (target)
  (let ((parts (split-string (string-trim-left target) " ")))
    (goto-line (string-to-number (nth 0 parts)))))

;;;###autoload
(defun fzf-find-in-buffer ()
  "Exact search in current buffer."
  (interactive)
  (fzf-with-command-and-args (concat "cat -n " buffer-file-name " | tac")
		    #'fzf/action-goto-line
        "--exact"))

wrong-type-argument stringp nil error

Hi,
My M-x fzf gives these following error message (found in the backtrace buffer):

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  make-process(:name "fzf" :buffer #<buffer *fzf*> :command ("/bin/sh" "-c" "stty -nl echo rows 12 columns 102 sane 2>/dev/null;if [ $1 = .. ]; then shift; fi; exec \"$@\"" ".." "sh" "-c" "fzf -x --color bw --print-query --margin=1,0"))
  apply(make-process (:name "fzf" :buffer #<buffer *fzf*> :command ("/bin/sh" "-c" "stty -nl echo rows 12 columns 102 sane 2>/dev/null;if [ $1 = .. ]; then shift; fi; exec \"$@\"" ".." "sh" "-c" "fzf -x --color bw --print-query --margin=1,0")))
  start-process("fzf" #<buffer *fzf*> "/bin/sh" "-c" "stty -nl echo rows 12 columns 102 sane 2>/dev/null;if [ $1 = .. ]; then shift; fi; exec \"$@\"" ".." "sh" "-c" "fzf -x --color bw --print-query --margin=1,0")
  apply(start-process "fzf" #<buffer *fzf*> "/bin/sh" "-c" "stty -nl echo rows 12 columns 102 sane 2>/dev/null;if [ $1 = .. ]; then shift; fi; exec \"$@\"" ".." "sh" ("-c" "fzf -x --color bw --print-query --margin=1,0"))
  term-exec-1("fzf" #<buffer *fzf*> "sh" ("-c" "fzf -x --color bw --print-query --margin=1,0"))
  term-exec(#<buffer *fzf*> "fzf" "sh" nil ("-c" "fzf -x --color bw --print-query --margin=1,0"))
  make-term("fzf" "sh" nil "-c" "fzf -x --color bw --print-query --margin=1,0")
  fzf/start(nil)
  fzf()
  funcall-interactively(fzf)
  call-interactively(fzf record nil)
  command-execute(fzf record)
  execute-extended-command(nil "fzf" "fzf")
  funcall-interactively(execute-extended-command nil "fzf" "fzf")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

My setup:

  • OS: Manjaro Linux
  • Emacs: GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.10)
    of 2019-08-30

Please help.

How can I pass arguments?

Note: I am using spacemacs with evil

How can I pass args to fzf so that I can enable C-j and C-k to select items as in NeoVim or terminal?

In spacemacs the screen is not rendered properly (as can be seen in the screenshot). I wonder if passing --colors arg could solve this or it is caused by some spacemacs config?

screen shot 2015-10-02 at 21 50 07

I am new to emacs, sorry If I am asking something obvious :)

FZF not working with Emacs 24.4

Getting this error (when running ":fzf" after "emacs -nw"):

/home/michael/.fzf/fzf:929:in `get_input': undefined method `getc' for nil:NilClass (NoMethodError)

If I run "M-x fzf" in a normal emacs (gui) window, the screen just flashes for a millisecond and then gives no output.

Would be great to have fzf working here, any input would be appreciated.

Proposal: Refactoring to fuzzy everything

@bling I know you prefer helm or counsel for many things, but what do you think about having Fzf as another option for fuzzing matching?

I like counsel, but helm don't. Helm freezes every single time with me. Fzf is blazing fast and could be used for:

  • files
  • grep (git-grep, ag, pt, etc)
  • buffer lines
  • buffer list
  • recent files
  • themes
  • ...you name here

I believe it can coexist with others, and you pick up what is better for you.
I would like to help, but let me know what you think, first.

Map ESC to keyboard-quit for FZF window?

Apologies for the noob question, but is there a way to have ESC close the FZF window, I've been trying to define something like the following:

(add-hook 'fzf-mode-hook (lambda ()
  (define-key fzf-mode-map (kbd "ESC") 'keyboard-quit))

But from the source code it doesn't look like there's anything like an FZF mode to hook into. Is that right? If so, is there something else I could hook into?

Thanks in advance!

fzf for buffers?

It would be great to have a fzf-buffers command that lets a user choose buffers through the fzf interface.

First 2 lines are invisible.(in GUI emacs)

If you go up above first line from fzf file list, you can see first 2 lines are invisible.
There are 2 lines above the window and cursor moves up there without list refreshing.
This is happening only on GUI emacs.

Several functions are identified as interactive but fail when launched interactively

The following functions are identified as being interactive in their code as well as in the comments but if one tries to launch them with M-x they fail lacking proper arguments:

  • fzf-with-command : expects between 2 to 5 arguments but receives none.
  • fzf-with-entries : expects between 2 to 3 arguments but receives none.

Also fzf-close is really an internal function but it's declared interactive. It's not autoloaded. If a user wants to use it it's possible to use it with eval via M-:

Turn off evil?

I think it relates to #45 a bit.

I would like fzf to turn-off evil mode in the fzf window so that I could use ctrl-p and ctrl-n to move up and down rather than trying to autocomplete. I made the change locally by adding (turn-off-evil-mode) here. Would you accept such change as a PR? Or, maybe, it should be configurable?

how to set $FZF_DEFAULT_COMMAND

in my .zshrc I have this

export FZF_DEFAULT_COMMAND='(git ls-tree -r --name-only HEAD || ag -l --nocolor -g "") 2> /dev/null'

How do I set this in fzf.el?

Grepping text inside of another directory using fzf+rg

Hi!

Thanks for the project!

Often times I need to search for specific strings in other directories. The fzf-grep command will perform the search, but only in the current directory.

So the requirements are:

  • the user should be able to set the root directory of the search
  • fzf + rg should be used starting from that root directory

The former is fixed easily, just ask the user for a directory.
To accomodate for the second requirement, I used the commands shown in the Interactive ripgrep integration section from the fzf repo [1].

My solution so far is a bit hacky, but it works. It looks like this:

(defun fzf-grep-in-dir ()
  (interactive)
  (let ((fzf/args "-x --color bw --print-query --margin=1,0 --no-hscroll --bind \"change:reload:rg --column --line-number --no-heading --smart-case {q} || true\" ")
        (action #'fzf/action-find-file-with-line)
        (dir (read-directory-name "Directory: " fzf/directory-start)))
    ;;(fzf-with-command "rg --column --line-number --no-heading --smart-case ''" action dir)
    (fzf/start dir action "rg --column --line-number --no-heading --smart-case ''")
    ))

The fzf-with-command function can be used instead of fzf/start, since the former is just a wrapper around the latter.

Is there a better alternative to this that could be implemented in fzf.el in the future?

Thanks!

Working directory is changed when opening file with fzf

If I use M-x fzf to find a file and I open it, my working directory is changed to the folder of the opened file. This means that when I later want to use fzf again, the search is very limited. Is there a setting to disable this?

setq-local in old-version emacs has arguments error

Emacs Version Info

GNU Emacs 26.1
Copyright (C) 2018 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Operation

M-x fzf-find-file

Error Info

setq-local: Wrong number of arguments: (2 . 2), 12

when I use the master version of fzf.el, the error occur every time, but if I use the fzf.el in the elpa, there is no problem. So I compare the code of master and elpa, then found different usage of setq-local.

In elpa. it's

    (setq-local scroll-margin 0)
    (setq-local scroll-conservatively 0)
    (setq-local term-suppress-hard-newline t)
    (setq-local show-trailing-whitespace nil)
    (setq-local display-line-numbers nil)
    (setq-local truncate-lines t)

In master, it's

    (setq-local scroll-margin 0
                scroll-conservatively 0
                term-suppress-hard-newline t
                show-trailing-whitespace nil
                display-line-numbers nil
                truncate-lines t)

And in older version of eamcs(before emacs 27), setq-local not support the multi arguments usage.
So I think for the user of fzf.el who are using old version Emacs, maybe we should revert the code which defines setq-local variable.

error in process filter

I get this error

error in process filter: face-attribute: Invalid face: unspecified
error in process filter: Invalid face: unspecified

emacs version:

GNU Emacs 25.1.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.22.7) of 2017-02-07

fzf version 0.16.6

fzf.el version 20161226.936

thanks

fzf is not working on remote directory.

fzf only shows the result of local directory.
I think it is necessary to update the part of (make-term "fzf" "sh" nil "-c" sh-cmd) but couldn't figure out how yet.
I'll appreciate for any thoughts or hint.
Thanks.

fzf target files occasionally fail to open

When I run M-x fzf RET and then find a file match which is a valid file but not an open buffer already, no new buffer is opened but the string target <the thing i matched> is displayed in the minibuffer.

Is this expected behavior?

Open multiple files in once?

A small idea :

why not able to open multiple files in once using the -m option of fzf which allows to select multiple files??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.