junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.4k stars 2.36k forks source link

FZF_DEFAULT_OPTS not respected in neovim #3697

Closed thyssentishman closed 5 months ago

thyssentishman commented 5 months ago

Checklist

Output of fzf --version

0.46.1

OS

Shell

Problem / Steps to reproduce

For some reason when running :FZF inside neovim, the FZF_DEFAULT_OPTS are not being respected. I have the following (almost default) configuration:

vim.keymap.set('n', '<Leader>f', '<CMD>FZF<CR>')
vim.g.fzf_layout = { down = '30%' }
vim.g.fzf_action = {
    ['ctrl-t'] = 'tab split',
    ['ctrl-v'] = 'split',
    ['ctrl-h'] = 'vsplit',
}

local fzf_group = vim.api.nvim_create_augroup("fzf_group", { clear = true })
vim.api.nvim_create_autocmd('FileType', {
    pattern = 'fzf',
    group = fzf_group,
    callback = function(args)
        vim.o.laststatus = 0
        vim.o.showmode = false
        vim.o.ruler = false
        vim.api.nvim_create_autocmd('BufLeave', {
            group = fzf_group,
            callback = function(args)
                vim.o.laststatus = 2
                vim.o.showmode = true
                vim.o.ruler = true
            end
        })
    end
})

I'm using the fzf binary installed on my system and everything else works as expected. I've tried overriding the $FZF_DEFAULT_OPTS variables as suggested in #1715 but without success:

vim.cmd([[
let $FZF_DEFAULT_OPTS = "--height=40% --reverse --no-info --color='hl:14,hl+:11,fg+:7:regular:underline,pointer:10'"
]])

Not sure if this is related to neovim or fzf. Any ideas?

junegunn commented 5 months ago

It should work. Does :echo $FZF_DEFAULT_OPTS report the right value?

thyssentishman commented 5 months ago

It should work. Does :echo $FZF_DEFAULT_OPTS report the right value?

Yes it does, but for some reason it doesn't seem to be respected:

fzf_issue_2

You can see that the prompts are different, and that the selected line is highlighted with a different background. Do I have to manually override --promt and bg+?

thyssentishman commented 5 months ago

Do I have to manually override --promt and bg+?

Here is the results with those overrides:

fzf_issue_3

Better, but the prompt is still not correct. This also tells me that the vim plugin seems to be setting its own custom settings (different than the fzf regular defaults). If FZF_DEFAULT_OPTS doesn't override these, then we get what's happening here.

Can these vim custom settings be cleared and just use plain fzf defaults? Would it maybe be better to only use the vim plugin custom settings if FZF_DEFAULT_OPTS is not set?

thyssentishman commented 5 months ago

This also tells me that the vim plugin seems to be setting its own custom settings (different than the fzf regular defaults).

Okay this seems to be the case cause I'm using :FZF. Now I've change my keymap to the following and now it's working:

vim.keymap.set('n', '<Leader>f', '<CMD>call fzf#run(fzf#wrap())<CR>')

The --prompt override doesn't seem necessary now, but the bg+ does. With this change both fzf in the terminal and in vim look the same.

Closing issue.

junegunn commented 5 months ago

Yes, :FZF command does that for you because it allows you to pass a directory to start search from.

e.g. :FZF ~/, :FZF /tmp, etc.

https://github.com/junegunn/fzf/blob/dff865239a0cdc79f33e97ec900b2bc8dd6517d2/plugin/fzf.vim#L1085-L1087

If you don't like it, fzf#run(fzf#wrap()) is the right way.


Start :terminal inside Neovim, run fzf, and see if the colors look right. IIRC, Neovim terminal has its own color palette and you may need to override the colors.

See https://github.com/junegunn/fzf/blob/master/README-VIM.md#fzf-inside-terminal-buffer

thyssentishman commented 5 months ago

Thank you :)