Fzf: Toggling/different options for CTRL-R & CTRL-T?

Created on 12 Jun 2016  路  12Comments  路  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [x] Neovim

  • OS

    • [x] Mac OS X

  • Shell

    • [x] zsh

Is there is a way to have different options for CTRL+R and CTRL+T?

For example I want CTRL+T to always show preview --preview but I don't want this with CTRL+R?

currently this is my options

export FZF_DEFAULT_OPTS='--reverse --extended --tabstop=2 --cycle --no-mouse --preview "pygmentize {}" --color light --margin 1'
enhancement

Most helpful comment

I don't think one should put --preview in FZF_DEFAULT_OPTS as it only makes sense for a specific type of input. Anyway, I'll add FZF_CTRL_T_OPTS and FZF_ALT_C_OPTS so you can customize the options.

All 12 comments

I don't think one should put --preview in FZF_DEFAULT_OPTS as it only makes sense for a specific type of input. Anyway, I'll add FZF_CTRL_T_OPTS and FZF_ALT_C_OPTS so you can customize the options.

Thanks @junegunn

One last question, will the --preview flag work in neovim using fzf.vim? because it doesn't work if I do this

autocmd VimEnter * command! Files
  \ call fzf#vim#files({'options': '--preview "pygmentize -g {}" --color light --bind ?:toggle-preview'})

it returns this error
screen shot 2016-06-12 at 15 40 00

But it works if I have --preview "pygmentize -g {}" --color light --bind ?:toggle-preview as part of FZF_DEFAULT_OPTS

The first argument to the function is the base directory to start search. The options dictionary should be the second.

What if I want to keep everything as it is but just use different options? Do I need to duplicate the logic here?

No, the option in the dictionary you pass as the second argument will be appended to the default set of options.

Also note that the default Files command takes an optional directory argument which to me is quite useful, you may not want to lose the functionality. Refer to the definition of the command.

Thanks for pointing this out. My solution was actually about only passing the cwd to Files something like this but I think this will break the optional argument.

autocmd VimEnter * command! Files
  \ call fzf#vim#files(expand('%:p:h'), { 'window': 'aboveleft 20new', 'options': substitute(system("echo $FZF_CTRL_T_OPTS"), '\n\+$', '', '') })

If you see the definition of the original command, you'll realize that you only need to pass an empty string (<q-args> is empty when no argument is given) to start search from the current directory.

And substitute(system("echo $FZF_CTRL_T_OPTS"), '\n\+$', '', '') is a very long version of $FZF_CTRL_T_OPTS. Vim knows about env vars.

Awesome, thanks!

Everything is working fine except that when I define a custom Files command like above the colors of fzf.vim are missed up, any idea why? commenting it out returns everything as normal.

 autocmd VimEnter * command! Files
   \ call fzf#vim#files('', { 'window': 'aboveleft 20new', 'options': $FZF_CTRL_T_OPTS })

Hmm, I don't see the problem, please create a separate issue on fzf.vim project with a screenshot of the problem you're experiencing.

Was this page helpful?
0 / 5 - 0 ratings