linrongbin16/fzfx.nvim

Preview using nVim instead of `cat` or `bat`

Closed this issue · 14 comments

Is it technically possible? Having consistent colourscheme would be great.

Is it technically possible? Having consistent colourscheme would be great.

hi, it should be possible, but it requires a lot of effort, and I had once did a little investigation on the solution.

the nvim preview should be a nvim buffer and float window that open an read only file.

but now I still don't know how to do it.

the fzf-lua can do it, but I don't understand the source code. it should be the builtin previewer: https://github.com/ibhagwan/fzf-lua/blob/main/lua/fzf-lua/previewer/builtin.lua

the solution is relate to several things:

  • only show left side of fzf, without preview window.
  • adjust configuration, make it compatible for both fzf preview window and nvim buffer.
  • put the nvim buffer and fzf terminal together, and looks good.
  • make the nvim buffer connect with fzf left side, and can update when fzf scrolling.

it's also one of the very important feature I want to add to it, for very long time.

I will look into it.

the first buffer previewer work is at: #556

for now it can only preview file content (but I think it's the only major use case), without line number support (I will support line numbers for live grep in next PR).


The nvim buffer previewer is merged into main branch, but the key mappings (toggle-preview, scroll-half-page-down, etc) are not implemented.

I will do it in next PR.

hi @savchenko , after #557 and #564 been merged into main branch, can you take a look if current bat previewer is good enough?

I will say it's about 85% close to native nvim buffer.

The nvim buffer previewer is also usable, but it's still experimental, it's sometimes super laggy.

I am a little tired of maintaining two separated implementation of previewers, improve bat theme is much easier than nvim buffer. The nvim buffer eats a lof of effort and time, like a black hole.

Hi @linrongbin16, the last release does not behave as usual. For example, selecting multiple entries returns:

Error executing vim.schedule lua callback: ...l/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/strings.lua:180: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ...l/share/nvim/lazy/fzfx.nvim/lua/fzfx/commons/strings.lua:180: in function 'replace'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:536: in function '_render_theme'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:580: in function '_build_theme'
        ...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:641: in function <...hare/nvim/lazy/fzfx.nvim/lua/fzfx/detail/bat_helpers.lua:638

...and the search is now very particular about escape character (?!). Check this out:

image

...add a single bracket...

image

Might be an issue on my side, however I haven't touched fzfx config for some time.

hi @savchenko,

It looks like an exception throwed. But I cannot find the _render_theme function in current bat_helpers.lua.

can you check the git commit of the plugin you're using? seems it's not the latest main branch.

And also, please enable the debug mode with:

require('fzfx').setup({
  debug={
    enable=true,
    file_log=true,
  }
})

then upload the log here, and I will check.

hi @savchenko , this issue could be the same issue with #575 , and I just fixed it in #576 .

Would you please pull main branch and try again? see if this issue still exists.

Updated again, the error is gone. Further setting $BAT_THEME to one generated by fzfx.nvim results in a reasonably close match:

02-Feb_20-07-35

Updated again, the error is gone. Further setting $BAT_THEME to one generated by fzfx.nvim results in a reasonably close match:

02-Feb_20-07-35

It's automatically generated, you don't need to specify it in BAT_THEME

I am trying to improve the converter (from nvim syntax to TextMate theme) again and again, to make it closer.

The issue with ( breaking the search functionality is still present though.

Attaching fzfx.log: fzfx.log

Content of the _live_grep_last_query_cache:

{"default_provider":"restricted_mode","query":"vim.fn.expand("}

It's automatically generated, you don't need to specify it in BAT_THEME

I define BAT_THEME in ~/.profile and unless it's set to the generate theme, one in the ~/.profile takes precedence.

The issue with ( breaking the search functionality is still present though.

Attaching fzfx.log: fzfx.log

Content of the _live_grep_last_query_cache:

{"default_provider":"restricted_mode","query":"vim.fn.expand("}

hi @savchenko ,

image

when you type vim.fn.expand(, the rg command actually executed in the underground is rg --column -n --no-heading --color=always -H -S -- vim.fn.expand(.

If you type above command in your terminal, it's true that there's nothing output from rg.

To solve this issue, you could enter vim.fn.expand( -- -F in this plugin. it will run below commands in the underground:

rg --column -n --no-heading --color=always -H -S -F -- vim.fn.expand(

And it will search vim.fn.expand( for you.

Also type rg --help for more details about -F option.

#591 is merged into main branch, close this ticket for now. I will enable buffer previewer for more and more commands in follow PRs.