1

Here's what I'd like to do, and I'm open to using any tool (not just fzf):

I want to be able to open a new file quickly (with a horizontal split :sp) in a specific directory that I find using fzf. Say we're working with this structure

foo/
  bar/
    file.js
  poop/

While I have file.js open in my buffer, I should be able to fuzzy find the foo/poop/ directory and open a new file foo/poop/newfile.js in a split window.

0

Using fzf.vim, it has the wrapper for Files, (and GFiles, which respect the gitignore while searching)

Under current directory, run :Files, fzf will open a list of files to search. Remember, this only search file names, not file's contents.

Hit c-x for split, or c-v for vsplit.

If you want to preview the content inside the file, set this in .vimrc:

" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)

It will show the preview content next to the search list.

I set the shortcut to sf (in my mind, it is search files, so I can quickly open it)

nmap <silent> sf :FzfFiles<cr>

If you want to search the content inside the files, use :Ag.

Read the fzf.vim documentation for more information.

0

I ended up using this command in my vimrc with fzf.vim, specifically filtering directories in my current git repo.

function! s:append_dir_with_fzf(line)
  call fzf#run(fzf#wrap({
    \ 'options': ['--prompt', a:line.'> '],
    \ 'source': 'git ls-files $(git rev-parse --show-toplevel) | xargs -n 1 dirname | uniq',
    \ 'sink': {line -> feedkeys("\<esc>:".a:line.line, 'n')}}))
  return ''
endfunction

cnoremap <expr> <c-x><c-d> <sid>append_dir_with_fzf(getcmdline())

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.