How to enable "fd" in neovim

I am using “fd” as my fd tool in my command line. I want to enable the use of “fd” in neovim instead of the normal “find” command in neovim. I have installed fd in my plugins with my package manager and am using the latest neovim nightly, but does seem get the fd" command working in neovim instead of “find”

How do I configure the use of “fd” in neovim

I have something like this in my config:

function! s:CompleteFd(arglead, cmdline, cursorpos) abort
    let cmd = "fd -t f -g '" . a:arglead . "'"
    let results = systemlist(cmd)
    return results

command! -nargs=1 -complete=customlist,<sid>CompleteFd FD execute 'edit' <f-args>

You can call :FD <tab> and it will complete existing files in the current directory.


Thank you. I have hit a small issue when I have put this in my init.lua file I am having error which says


I am using the latest version of neovim nightly.

Yo, this command instruction is gonna help my plugin. I always wanted to use a s: function as a custom complete function, but I never knew how. I always tried -complete=customlist,s:CompleteFd. Now I know why it didn’t work.

Thank you.

1 Like

You could try the following snippet if using init.lua. It uses a global function, because AFAIK there’s no way to use a Lua local function for command completion.

function _G.complete_fd(arglead, cmdline, cursorpos)
    local cmd = "fd -t f -g '" .. arglead .. "'"
    local results = vim.fn.systemlist(cmd)
    return results

    command! -nargs=1 -complete=customlist,v:lua.complete_fd FD execute 'edit' <f-args>
]], false)

Thank you it works now

1 Like