1

Faced a problem that I cannot force the buffer with results and the input field to work together, but not in turn (like in CtrlP)

function! s:SearchByListFiles(all_files, query)
    let searched = []
    for filepath in a:all_files
        if a:query == '' || len(split(filepath, a:query)) > 1
            call add(searched, filepath)
        endif
    endfor
    return searched
endfunc

function! s:GetListLocalFiles(local_path)
    let list_local_files_cmd = 'find ' . a:local_path . ' -type f'                                                          
    let all_local_files = split(system(list_local_files_cmd), '\n')
    return all_local_files 
endfunc

function! s:SearchFinderDialog(all_files, query)
    silent! execute "botright pedit ls"
    noautocmd wincmd P
    set buftype=nofile

    let all_files = a:all_files
    if all_files == []
        let all_files = s:GetListLocalFiles(getcwd())
    endif

    for filepath in s:SearchByListFiles(all_files, a:query)
        silent! execute "r! echo " . filepath
    endfor
    silent! execute "redraw!"

    let search_query = input('>>> ')
    call s:SearchFinderDialog(all_files, search_query)
endfunc

command! -nargs=? SearchFinderDialog :call s:SearchFinderDialog([], "")

I want the arrows (up, down) to control the selection of the file, and typing occurs in the input field

enter image description here

  • 1
    (1) why the recursion in your function? (2) youll probably need to give s:GetMatchedFiles or otherwise trim the example down so answerers can reproduce your code/problem. (3) if you want CtrlP-like behavior, why not read/borrow some of its code? – D. Ben Knoble Jun 5 at 21:57
  • I suggest you would try FZF. And also CTRL-P does it already. But FZF is more customizable. – eyal karni Jun 10 at 22:21
  • My task is to write the plugin myself, I just can't get the right behavior from the input line – shotinleg Jun 11 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.