From f5b77fdeb20368b3bb96961b3655b6029c22108a Mon Sep 17 00:00:00 2001 From: suitablebeard <122230735+suitablebeard@users.noreply.github.com> Date: Wed, 20 May 2026 16:31:56 -0300 Subject: [PATCH] feat: search for files or string in the specified directory Now you can fuzzy search in a different directory. Otherwise you would need to cd into it. --- README.md | 2 ++ autoload/fuzzbox/builtin/files.vim | 2 +- autoload/fuzzbox/builtin/grep.vim | 2 +- autoload/fuzzbox/internal/helpers.vim | 4 ++++ plugin/fuzzbox.vim | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de4bce4..af5f4b9 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,10 @@ git clone https://github.com/vim-fuzzbox/fuzzbox.vim ~/.vim/pack/plugins/start/f | --- | --- | FuzzyFiles | search files in current working directory (CWD) | FuzzyFilesRoot | search files in the project/vcs root directory +| FuzzyFilesDir [path] | search files in the specified directory | FuzzyGrep [str] | search for string in CWD, use [str] if provided | FuzzyGrepRoot [str] | search for string in the project/vcs root directory +| FuzzyGrepDir [path] | search for string in the specified directory | FuzzyBuffers | search opened buffers | FuzzyMru | search most recent used files | FuzzyMruCwd | search most recent used files in CWD diff --git a/autoload/fuzzbox/builtin/files.vim b/autoload/fuzzbox/builtin/files.vim index fbe44b8..09b9054 100644 --- a/autoload/fuzzbox/builtin/files.vim +++ b/autoload/fuzzbox/builtin/files.vim @@ -117,7 +117,7 @@ export def Start(opts: dict = {}) cur_result = [] cur_pattern = '' last_pattern = '@!#-=' - cwd = len(get(opts, 'cwd', '')) > 0 ? opts.cwd : getcwd() + cwd = len(get(opts, 'cwd', '')) > 0 ? helpers.ParsePath(opts.cwd) : getcwd() in_loading = 1 var wids = selector.Start([], extend(opts, { select_cb: actions.OpenFile, diff --git a/autoload/fuzzbox/builtin/grep.vim b/autoload/fuzzbox/builtin/grep.vim index eb3ac07..f9dfe25 100644 --- a/autoload/fuzzbox/builtin/grep.vim +++ b/autoload/fuzzbox/builtin/grep.vim @@ -264,7 +264,7 @@ export def Start(opts: dict = {}) [cmd_template, sep_pattern, ignore_case] = cmdbuilder.Build() endif - cwd = len(get(opts, 'cwd', '')) > 0 ? opts.cwd : getcwd() + cwd = len(get(opts, 'cwd', '')) > 0 ? helpers.ParsePath(opts.cwd) : getcwd() cwdlen = len(cwd) cur_pattern = '' cur_result = [] diff --git a/autoload/fuzzbox/internal/helpers.vim b/autoload/fuzzbox/internal/helpers.vim index 2f4ccf0..7a10fdb 100644 --- a/autoload/fuzzbox/internal/helpers.vim +++ b/autoload/fuzzbox/internal/helpers.vim @@ -86,3 +86,7 @@ export def MoveToUsableWindow(buf: any = null) c = c + 1 endwhile enddef + +export def ParsePath(path: string): string + return simplify(expand(path)) +enddef diff --git a/plugin/fuzzbox.vim b/plugin/fuzzbox.vim index e47d209..d2a7ef0 100644 --- a/plugin/fuzzbox.vim +++ b/plugin/fuzzbox.vim @@ -86,8 +86,10 @@ import autoload '../autoload/fuzzbox/internal/helpers.vim' command! -nargs=? FuzzyGrep launcher.Start('grep', { prompt_text: }) command! -nargs=? FuzzyGrepRoot launcher.Start('grep', { cwd: helpers.GetRootDir(), prompt_text: }) +command! -nargs=1 FuzzyGrepDir launcher.Start('grep', { cwd: }) command! -nargs=0 FuzzyFiles launcher.Start('files') command! -nargs=0 FuzzyFilesRoot launcher.Start('files', { cwd: helpers.GetRootDir() }) +command! -nargs=1 FuzzyFilesDir launcher.Start('files', { cwd: }) command! -nargs=0 FuzzyHelp launcher.Start('help') command! -nargs=0 FuzzyColors launcher.Start('colors') command! -nargs=? FuzzyInBuffer launcher.Start('inbuffer', { prompt_text: })