Objective:
I wanted a way to open a project from within VIM in a new tab using the fzf#run feature of fzf - and I found what I think will be a great solution- namely:
" ~/.vimrc
nnoremap <silent><leader>p :call fzf#run({ 'source': 'listprojects', 'sink': 'tabedit'})<CR>
# ~/.zshrc
# list all directories that contain a `package.json`
listprojects() {
find /Users/username/. -maxdepth 2 -name package.json -print0 | xargs -0 -n1 dirname | sort --unique
}
!listprojects in vim I get what I expect to see.!listprojects | fzf in vim I get no results but fzf loadsWhen hitting <leader><p> I get no results but fzf loads
Question:
How should I modify my source parameter (or anything else for that matter) to achieve this?
Bonus Info
listprojects into a function within .zshrc because I got all kinds of problems when I tried including the raw command, pipes and all, in the source parameter's string value.call fzf#run({'source': 'ls | cat'}) works as expected. The reason you had trouble with |s is that with map commands, Vim interprets a bar character as a command separator (like ; in most other languages), so you have to write them as <bar>, which is going to be quite awkward. It's much simpler if you just define a custom function with plain |s and call it from the mapping.
function! s:foo()
call fzf#run(fzf#wrap({'source': 'ls | cat'}))
endfunction
nnoremap <silent><leader>p :call <sid>foo()<cr>
For a shell function to be available in Vim, you'll have to properly export it.
Most helpful comment
call fzf#run({'source': 'ls | cat'})works as expected. The reason you had trouble with|s is that withmapcommands, Vim interprets a bar character as a command separator (like;in most other languages), so you have to write them as<bar>, which is going to be quite awkward. It's much simpler if you just define a custom function with plain|s and call it from the mapping.For a shell function to be available in Vim, you'll have to properly export it.