Find a file (via recursive directory search) in Vim

后端 未结 15 1245
感情败类
感情败类 2020-12-22 18:42

Is there any way to search a directory recursively for a file (using wildcards when needed) in Vim? If not natively, is there a plugin that can handle this?

15条回答
  •  忘掉有多难
    2020-12-22 19:10

    You don't need a plugin only for this function, below code snippet is enough.

    function! FindFiles()
        call inputsave()
        let l:dir = input("Find file in: ", expand("%:p:h"), "dir")
        call inputrestore()
        if l:dir != ""
            call inputsave()
            let l:file = input("File name: ")
            call inputrestore()
            let l:nf = 'find '.l:dir.' -type f -iname '.l:file.' -exec grep -nH -m 1 ".*" {} \;'
            lexpr system(l:nf)
        endif
    endfunction
    nnoremap  fo :call FindFiles()
    

提交回复
热议问题