Opening files in Vim using Fuzzy Search

前端 未结 4 2132
栀梦
栀梦 2021-01-30 04:01

I\'m looking for a way to make Vim have the ability to open a file by fuzzy-searching its name.

Basically, I want to be able to define a project once, and then have a sh

4条回答
  •  囚心锁ツ
    2021-01-30 04:27

    Basic solution

    Simply add this to your .vimrc

    nnoremap  :find ./**/*
    

    Pressing Ctrl+p will now allow you to fuzzyfind files in your current working directory and sub-directories thereof. Use the tab key to cycle through options.

    Related solution

    For those who want to keep it basic i.e. no plugins, this entertaining video shows another way to achieve fuzzy file find in vim.

    They actually use

    set path+=**
    set wildmenu
    

    in their .vimrc to find files in current sub-directories.

    For example, with :find *Murph followd by tab, I would find the files KilianMurphy2012Why.R and KilianMurphy2014ROLE.R in subdir code which I can cycle through with the tab key. The first solution above has the advantage that the relative path is also shown.

    Note that your current working directory will matter and that other files on your path (:set path?) will also be found with the this type of solution. The wildmenu option adds visual information and is not essential.

    For a keyboard shortcut, add

    nnoremap  :find *
    

    to your .vimrc. Now you will be able to quickly search for files inside your project/current dir with Ctrl+p in normal mode.

提交回复
热议问题