Getting started with fzf on Arch Linux












4














I just installed fzf on Arch Linux 4.13.11 using pacman -S fzf.



From bash, I can call fzf which lets me select files (using Ctrl + n and Ctrl + p) in the current directory and its subdirectories.



This is nice, but I'd like to have bash integration of some sort.



Where do I go from here?










share|improve this question





























    4














    I just installed fzf on Arch Linux 4.13.11 using pacman -S fzf.



    From bash, I can call fzf which lets me select files (using Ctrl + n and Ctrl + p) in the current directory and its subdirectories.



    This is nice, but I'd like to have bash integration of some sort.



    Where do I go from here?










    share|improve this question



























      4












      4








      4







      I just installed fzf on Arch Linux 4.13.11 using pacman -S fzf.



      From bash, I can call fzf which lets me select files (using Ctrl + n and Ctrl + p) in the current directory and its subdirectories.



      This is nice, but I'd like to have bash integration of some sort.



      Where do I go from here?










      share|improve this question















      I just installed fzf on Arch Linux 4.13.11 using pacman -S fzf.



      From bash, I can call fzf which lets me select files (using Ctrl + n and Ctrl + p) in the current directory and its subdirectories.



      This is nice, but I'd like to have bash integration of some sort.



      Where do I go from here?







      bash vim






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 '17 at 17:24









      jasonwryan

      49.2k14134184




      49.2k14134184










      asked Nov 11 '17 at 15:29









      Matthias Braun

      1,90321321




      1,90321321






















          1 Answer
          1






          active

          oldest

          votes


















          5














          Default bash key bindings



          Using whereis fzf, I found fzf's files for bash integration in usr/share/fzf:



          completion.bash
          key-bindings.bash


          After sourceing both files, this enables a couple of keybindings for bash: For example, I can hit Ctrl + t to search files in the current directory and Ctrl + r to search my command history.



          For finding and changing to a directory, there's Alt + c.



          To make these key bindings persistent, I added them to my .bashrc:



          source /usr/share/fzf/completion.bash && source /usr/share/fzf/key-bindings.bash


          Customization



          A customization I find useful is showing a file preview when using fzf (I put that in my .bashrc as well):



          # When selecting files with fzf, we show file content with syntax highlighting,
          # or without highlighting if it's not a source file. If the file is a directory,
          # we use tree to show the directory's contents.
          # We only load the first 200 lines of the file which enables fast previews
          # of large text files.
          # Requires highlight and tree: pacman -S highlight tree
          export FZF_DEFAULT_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null ||
          cat {} || tree -C {}) 2> /dev/null | head -200'"


          Path completion



          Out of the box, fzf supports fuzzy path completion for a couple of hard-coded commands like cd, ls, and vim.



          For example, entering vim ** Tab on bash starts a fuzzy search in the current directory and opens the selected file with Vim1.



          This is pretty useful, but I'd like to open, for example, PDFs the same way. You can enable this by adding the following line to .bashrc:



          complete -o bashdefault -o default -F _fzf_path_completion zathura


          Here, zathura is my PDF viewer; you can substitute it with the document viewer of your choice.



          Note that fuzzy path completion works for all paths, not only the current directory:



          vim ~/**


          and then hitting Tab will fuzzy-search a file under your home directory and then open it in Vim.



          Vim integration



          Here are some keybindings from my .vimrc to use fzf inside a Vim session:



          " Search and switch buffers
          nmap <leader>b :Buffers<cr>
          " Find files by name under the current directory
          nmap <leader>f :Files<cr>
          " Find files by name under the home directory
          nmap <leader>h :Files ~/<cr>
          " Search content in the current file
          nmap <leader>l :BLines<cr>
          " Search content in the current file and in files under the current directory
          nmap <leader>g :Ag<cr>


          Prerequisite for all that is the fzf Vim plugin; I installed it with Vundle by putting this in my .vimrc:



          Plugin 'junegunn/fzf.vim'


          and then calling :PluginInstall from Vim.



          Here is a list of fzf commands you can call from Vim.



          Going further



          For a powerful combination of fzf, Vim, and Tmux, check out Keegan Lowenstein's blog post (I got the --preview configuration from there).



          Here are some ideas on how to configure fzf's shell integration.



          You can find more examples of fzf configuration in fzf's readme and in its wiki.



          1 If you find yourself fuzzy-searching files and then opening them in Vim a lot, you can create a keybinding for that using this piece of .bashrc.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403916%2fgetting-started-with-fzf-on-arch-linux%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            5














            Default bash key bindings



            Using whereis fzf, I found fzf's files for bash integration in usr/share/fzf:



            completion.bash
            key-bindings.bash


            After sourceing both files, this enables a couple of keybindings for bash: For example, I can hit Ctrl + t to search files in the current directory and Ctrl + r to search my command history.



            For finding and changing to a directory, there's Alt + c.



            To make these key bindings persistent, I added them to my .bashrc:



            source /usr/share/fzf/completion.bash && source /usr/share/fzf/key-bindings.bash


            Customization



            A customization I find useful is showing a file preview when using fzf (I put that in my .bashrc as well):



            # When selecting files with fzf, we show file content with syntax highlighting,
            # or without highlighting if it's not a source file. If the file is a directory,
            # we use tree to show the directory's contents.
            # We only load the first 200 lines of the file which enables fast previews
            # of large text files.
            # Requires highlight and tree: pacman -S highlight tree
            export FZF_DEFAULT_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null ||
            cat {} || tree -C {}) 2> /dev/null | head -200'"


            Path completion



            Out of the box, fzf supports fuzzy path completion for a couple of hard-coded commands like cd, ls, and vim.



            For example, entering vim ** Tab on bash starts a fuzzy search in the current directory and opens the selected file with Vim1.



            This is pretty useful, but I'd like to open, for example, PDFs the same way. You can enable this by adding the following line to .bashrc:



            complete -o bashdefault -o default -F _fzf_path_completion zathura


            Here, zathura is my PDF viewer; you can substitute it with the document viewer of your choice.



            Note that fuzzy path completion works for all paths, not only the current directory:



            vim ~/**


            and then hitting Tab will fuzzy-search a file under your home directory and then open it in Vim.



            Vim integration



            Here are some keybindings from my .vimrc to use fzf inside a Vim session:



            " Search and switch buffers
            nmap <leader>b :Buffers<cr>
            " Find files by name under the current directory
            nmap <leader>f :Files<cr>
            " Find files by name under the home directory
            nmap <leader>h :Files ~/<cr>
            " Search content in the current file
            nmap <leader>l :BLines<cr>
            " Search content in the current file and in files under the current directory
            nmap <leader>g :Ag<cr>


            Prerequisite for all that is the fzf Vim plugin; I installed it with Vundle by putting this in my .vimrc:



            Plugin 'junegunn/fzf.vim'


            and then calling :PluginInstall from Vim.



            Here is a list of fzf commands you can call from Vim.



            Going further



            For a powerful combination of fzf, Vim, and Tmux, check out Keegan Lowenstein's blog post (I got the --preview configuration from there).



            Here are some ideas on how to configure fzf's shell integration.



            You can find more examples of fzf configuration in fzf's readme and in its wiki.



            1 If you find yourself fuzzy-searching files and then opening them in Vim a lot, you can create a keybinding for that using this piece of .bashrc.






            share|improve this answer




























              5














              Default bash key bindings



              Using whereis fzf, I found fzf's files for bash integration in usr/share/fzf:



              completion.bash
              key-bindings.bash


              After sourceing both files, this enables a couple of keybindings for bash: For example, I can hit Ctrl + t to search files in the current directory and Ctrl + r to search my command history.



              For finding and changing to a directory, there's Alt + c.



              To make these key bindings persistent, I added them to my .bashrc:



              source /usr/share/fzf/completion.bash && source /usr/share/fzf/key-bindings.bash


              Customization



              A customization I find useful is showing a file preview when using fzf (I put that in my .bashrc as well):



              # When selecting files with fzf, we show file content with syntax highlighting,
              # or without highlighting if it's not a source file. If the file is a directory,
              # we use tree to show the directory's contents.
              # We only load the first 200 lines of the file which enables fast previews
              # of large text files.
              # Requires highlight and tree: pacman -S highlight tree
              export FZF_DEFAULT_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null ||
              cat {} || tree -C {}) 2> /dev/null | head -200'"


              Path completion



              Out of the box, fzf supports fuzzy path completion for a couple of hard-coded commands like cd, ls, and vim.



              For example, entering vim ** Tab on bash starts a fuzzy search in the current directory and opens the selected file with Vim1.



              This is pretty useful, but I'd like to open, for example, PDFs the same way. You can enable this by adding the following line to .bashrc:



              complete -o bashdefault -o default -F _fzf_path_completion zathura


              Here, zathura is my PDF viewer; you can substitute it with the document viewer of your choice.



              Note that fuzzy path completion works for all paths, not only the current directory:



              vim ~/**


              and then hitting Tab will fuzzy-search a file under your home directory and then open it in Vim.



              Vim integration



              Here are some keybindings from my .vimrc to use fzf inside a Vim session:



              " Search and switch buffers
              nmap <leader>b :Buffers<cr>
              " Find files by name under the current directory
              nmap <leader>f :Files<cr>
              " Find files by name under the home directory
              nmap <leader>h :Files ~/<cr>
              " Search content in the current file
              nmap <leader>l :BLines<cr>
              " Search content in the current file and in files under the current directory
              nmap <leader>g :Ag<cr>


              Prerequisite for all that is the fzf Vim plugin; I installed it with Vundle by putting this in my .vimrc:



              Plugin 'junegunn/fzf.vim'


              and then calling :PluginInstall from Vim.



              Here is a list of fzf commands you can call from Vim.



              Going further



              For a powerful combination of fzf, Vim, and Tmux, check out Keegan Lowenstein's blog post (I got the --preview configuration from there).



              Here are some ideas on how to configure fzf's shell integration.



              You can find more examples of fzf configuration in fzf's readme and in its wiki.



              1 If you find yourself fuzzy-searching files and then opening them in Vim a lot, you can create a keybinding for that using this piece of .bashrc.






              share|improve this answer


























                5












                5








                5






                Default bash key bindings



                Using whereis fzf, I found fzf's files for bash integration in usr/share/fzf:



                completion.bash
                key-bindings.bash


                After sourceing both files, this enables a couple of keybindings for bash: For example, I can hit Ctrl + t to search files in the current directory and Ctrl + r to search my command history.



                For finding and changing to a directory, there's Alt + c.



                To make these key bindings persistent, I added them to my .bashrc:



                source /usr/share/fzf/completion.bash && source /usr/share/fzf/key-bindings.bash


                Customization



                A customization I find useful is showing a file preview when using fzf (I put that in my .bashrc as well):



                # When selecting files with fzf, we show file content with syntax highlighting,
                # or without highlighting if it's not a source file. If the file is a directory,
                # we use tree to show the directory's contents.
                # We only load the first 200 lines of the file which enables fast previews
                # of large text files.
                # Requires highlight and tree: pacman -S highlight tree
                export FZF_DEFAULT_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null ||
                cat {} || tree -C {}) 2> /dev/null | head -200'"


                Path completion



                Out of the box, fzf supports fuzzy path completion for a couple of hard-coded commands like cd, ls, and vim.



                For example, entering vim ** Tab on bash starts a fuzzy search in the current directory and opens the selected file with Vim1.



                This is pretty useful, but I'd like to open, for example, PDFs the same way. You can enable this by adding the following line to .bashrc:



                complete -o bashdefault -o default -F _fzf_path_completion zathura


                Here, zathura is my PDF viewer; you can substitute it with the document viewer of your choice.



                Note that fuzzy path completion works for all paths, not only the current directory:



                vim ~/**


                and then hitting Tab will fuzzy-search a file under your home directory and then open it in Vim.



                Vim integration



                Here are some keybindings from my .vimrc to use fzf inside a Vim session:



                " Search and switch buffers
                nmap <leader>b :Buffers<cr>
                " Find files by name under the current directory
                nmap <leader>f :Files<cr>
                " Find files by name under the home directory
                nmap <leader>h :Files ~/<cr>
                " Search content in the current file
                nmap <leader>l :BLines<cr>
                " Search content in the current file and in files under the current directory
                nmap <leader>g :Ag<cr>


                Prerequisite for all that is the fzf Vim plugin; I installed it with Vundle by putting this in my .vimrc:



                Plugin 'junegunn/fzf.vim'


                and then calling :PluginInstall from Vim.



                Here is a list of fzf commands you can call from Vim.



                Going further



                For a powerful combination of fzf, Vim, and Tmux, check out Keegan Lowenstein's blog post (I got the --preview configuration from there).



                Here are some ideas on how to configure fzf's shell integration.



                You can find more examples of fzf configuration in fzf's readme and in its wiki.



                1 If you find yourself fuzzy-searching files and then opening them in Vim a lot, you can create a keybinding for that using this piece of .bashrc.






                share|improve this answer














                Default bash key bindings



                Using whereis fzf, I found fzf's files for bash integration in usr/share/fzf:



                completion.bash
                key-bindings.bash


                After sourceing both files, this enables a couple of keybindings for bash: For example, I can hit Ctrl + t to search files in the current directory and Ctrl + r to search my command history.



                For finding and changing to a directory, there's Alt + c.



                To make these key bindings persistent, I added them to my .bashrc:



                source /usr/share/fzf/completion.bash && source /usr/share/fzf/key-bindings.bash


                Customization



                A customization I find useful is showing a file preview when using fzf (I put that in my .bashrc as well):



                # When selecting files with fzf, we show file content with syntax highlighting,
                # or without highlighting if it's not a source file. If the file is a directory,
                # we use tree to show the directory's contents.
                # We only load the first 200 lines of the file which enables fast previews
                # of large text files.
                # Requires highlight and tree: pacman -S highlight tree
                export FZF_DEFAULT_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null ||
                cat {} || tree -C {}) 2> /dev/null | head -200'"


                Path completion



                Out of the box, fzf supports fuzzy path completion for a couple of hard-coded commands like cd, ls, and vim.



                For example, entering vim ** Tab on bash starts a fuzzy search in the current directory and opens the selected file with Vim1.



                This is pretty useful, but I'd like to open, for example, PDFs the same way. You can enable this by adding the following line to .bashrc:



                complete -o bashdefault -o default -F _fzf_path_completion zathura


                Here, zathura is my PDF viewer; you can substitute it with the document viewer of your choice.



                Note that fuzzy path completion works for all paths, not only the current directory:



                vim ~/**


                and then hitting Tab will fuzzy-search a file under your home directory and then open it in Vim.



                Vim integration



                Here are some keybindings from my .vimrc to use fzf inside a Vim session:



                " Search and switch buffers
                nmap <leader>b :Buffers<cr>
                " Find files by name under the current directory
                nmap <leader>f :Files<cr>
                " Find files by name under the home directory
                nmap <leader>h :Files ~/<cr>
                " Search content in the current file
                nmap <leader>l :BLines<cr>
                " Search content in the current file and in files under the current directory
                nmap <leader>g :Ag<cr>


                Prerequisite for all that is the fzf Vim plugin; I installed it with Vundle by putting this in my .vimrc:



                Plugin 'junegunn/fzf.vim'


                and then calling :PluginInstall from Vim.



                Here is a list of fzf commands you can call from Vim.



                Going further



                For a powerful combination of fzf, Vim, and Tmux, check out Keegan Lowenstein's blog post (I got the --preview configuration from there).



                Here are some ideas on how to configure fzf's shell integration.



                You can find more examples of fzf configuration in fzf's readme and in its wiki.



                1 If you find yourself fuzzy-searching files and then opening them in Vim a lot, you can create a keybinding for that using this piece of .bashrc.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 18 at 11:38

























                answered Nov 11 '17 at 15:29









                Matthias Braun

                1,90321321




                1,90321321






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403916%2fgetting-started-with-fzf-on-arch-linux%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre