Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Suggestion: fzf-tmux support #225

Closed
sirupsen opened this issue Nov 25, 2021 · 16 comments
Closed

Feature Suggestion: fzf-tmux support #225

sirupsen opened this issue Nov 25, 2021 · 16 comments
Labels
feature request New feature

Comments

@sirupsen
Copy link

sirupsen commented Nov 25, 2021

Thank you so much for writing fzf-lua! It's a fantastic library, and I've started adopting it in a few places as I move my config further towards the Nvim/Lua ecosystem. 🙏🏻

A blocker for me personally is that I've gotten addicted to using fzf-tmux with fzf.vim 😬

It's a separate binary that causes fzf to use tmux popup to create a floating window overlaying all panes (if you run fzf-tmux in your terminal, you'll see it). Here it inside Vim, configured in fzf.vim:

image

Versus fzf-lua:

image

This is absolute gold to take advantage of all your tmux real-estate, especially if you're using side-panels like I always do... For big repositories (i.e. long file paths, fully resolved ctags, large module hierarchies for LSP symbols) with previews, I need this with my setup because I don't full-screen nvim.

I know the way you've engineered fzf-lua, you're creating a floating window inside nvim to style, then putting fzf into it... which wouldn't work with this design. Secretly I'm hoping you might see the value in fzf-tmux for yourself and consider adding it 🙈 🙃

Either way, might serve as an issue to collect other people who might be interested (or maybe I'm on an island, it's not a very documented feature of fzf... so usage might be low. But it's so good).

@ibhagwan ibhagwan added the feature request New feature label Nov 25, 2021
@ibhagwan
Copy link
Owner

Ty @sirupsen, I didn’t know about fzf-tmux, always happy to learn new things.

I know the way you've engineered fzf-lua, you're creating a floating window inside nvim to style, then putting fzf into it... which wouldn't work with this design. Secretly I'm hoping you might see the value in fzf-tmux for yourself and consider adding it 🙈 🙃

You’re correct, the way it’s designed the main window and the builtin preview window are both using nvim_open_win API, additionally, many functionalities (preview toggle, full screen toggle, rotate, etc) all rely on neovim window API. Adapting to fzf-tmux require rewriting large chunk of the plug-in while still not being able to support some features, not very practical as you can imagine.

I understand where you’re coming from though, the way I deal with needing more real estate is this:

  • First I toggle fzf-lua full screen (default F2)
  • If my preview comes in the way I wither close it with F4 or rotate it left right with F5/6
  • If I still need more real estate I use “tmux zoom” with <prefix>-z, this makes my current pane take the entire tmux space

Hopefully this helps!

@sirupsen
Copy link
Author

sirupsen commented Nov 26, 2021

Thanks for your answer 🙏🏻 Appreciate your suggestions! I didn't know you could toggle fzf-lua full-screen, that's cool! I will give it a shot, but suspect it's not quite enough for me on a 13" and with how much I use tmux splits, but maybe...

Thanks for your consideration though, I'll close this as it's essentially a re-architecture for a feature you wouldn't use yourself, as I suspected. 👍🏻

@cpakkala
Copy link

cpakkala commented Jan 9, 2022

Either way, might serve as an issue to collect other people who might be interested (or maybe I'm on an island, it's not a very documented feature of fzf... so usage might be low. But it's so good).

FYI, you're not on an island. fzf-tmux is the center of my workflow as well, which is why I'm having to stick with fzf.vim. I keep running into this issue with plugins supporting nvim popups, but not tmux popups, yet I refuse to give up tmux popups. Ideally, it would be wonderful if there were a way to integrate vim popups with tmux popups; some kind of adapter. If I knew more about the internals of nvim itself, I might persue such a thing; but that's too lofty a goal for me as it stands. Anyway; cheers to tmux popups...

@ibhagwan
Copy link
Owner

ibhagwan commented Jan 9, 2022

FYI, you're not on an island. fzf-tmux is the center of my workflow as well, which is why I'm having to stick with fzf.vim.

@cpakkala, out of curiosity, how does fzf.vim handle tmux popups?

@cpakkala
Copy link

cpakkala commented Jan 9, 2022

FYI, you're not on an island. fzf-tmux is the center of my workflow as well, which is why I'm having to stick with fzf.vim.

@cpakkala, out of curiosity, how does fzf.vim handle tmux popups?

Instead of calling 'fzf', it calls 'fzf-tmux' ( https://github.com/junegunn/fzf/blob/master/bin/fzf-tmux ), which is just a wrapper that spawns the real fzf inside a new tmux popup pane. Obviously, this wouldn't support the vim window settings, but it makes my environment consistent whether in vim, zsh, or any other app that uses fzf-tmux.

I'm not averse to using tmux zoom; I use it all the time; however, having to zoom every single time I want to use an FZF-related binding (especially for zsh completions, etc.) gets old REAL fast. Tmux popups are indeed a godsend.

@ibhagwan
Copy link
Owner

ibhagwan commented Feb 11, 2023

@sirupsen, @cpakkala, a bit late but you if you're still interested this was just completed, I can't commit it yet as I'm behind a firewall which won't let me SSH auth so probably in a few hours:
image

To use:

require("fzf-lua").setup({
  fzf_bin = "fzf-tmux",
  -- make sure to set fzf-tmux specific flags (otherwise 80%:80% default is used)
  fzf_tmux_opts = {
    -- use tmux popup 80% width, 80% height (requires tmux >= 3.2)
    ["-p"] = "80%,80%",
  }
  -- You probably also want to change the default previewer as only native
  -- fzf previewers can work (obviously neovim windows are not possible)
  winopts = {
    preview = {
      default = "bat"
    }
  }
})

@ibhagwan
Copy link
Owner

Btw, another great option for fullscreen over tmux which I personally use to review git_status changes is to crests a custom command that first runa vim.cmd("!tmux resize-pane -Z"), this makes the current tmux pane fullscreen.

The above has the benefit of not being limited to native fzf previewers only, below is the code I use which automatically toggles fullscreen when exiting the function as well:
https://github.com/ibhagwan/nvim-lua/blob/fa8f0eefa90734bb613d173edaf7b792dbb40e2c/lua/plugins/fzf-lua/cmds.lua#L21-L46

@ibhagwan
Copy link
Owner

Added in 6369ae3, note that I edited the comment above, fzf-tmux specific flags should be configured in fzf_tmux_opts with the default being -p 80%,80% which opens in a tmux popup 80w on 80h.

@nyngwang
Copy link
Contributor

nyngwang commented Feb 12, 2023

@ibhagwan Thank you for achieving this feature! It's really valuable because <prefix>-z is inconvenient when I need to frequently jump between two(or more) tmux splits and I want one(or some) of the splits to be always "zoomed/maximized".


Btw, I just encountered a problem: I don't know how to make the popup has a solid-color background... (This is probably not a problem of fzf-lua since it's a tmux split. But it will be great if it is possible to send some commands/options from Neovim to specify the background color just for the tmux popup?)

@ibhagwan
Copy link
Owner

Btw, I just encountered a problem: I don't know how to make the popup has a solid-color background... (This is probably not a problem of fzf-lua since it's a tmux split. But it will be great if it is possible to send some commands/options from Neovim to specify the background color just for the tmux popup?)

You don’t necessarily need to change the tmux popup color, you can use fzf_colors to change the background color of fzf by adding ["bg"] = { "bg", "Normal" } (this will match the color of your neovim background).

@cpakkala
Copy link

Awesome; thank you very much ibhagwan. I will be adding back migration to fzf-lua to my todo list.

For those still considering the various "finder" projects (fzf-lua, telescope,etc.), I believe that the reason that they have become so popular is that they provide a CONSISTENT interface for all your query-type interactions with vim/nvim. Well, with fzf-tmux, you extend that consistency to your shell (zsh highly recommended with fzf) and everything else that you do in tmux, which for me, is everything besides web-browsing (and that could be done there as well, if I really wanted). It's like having one interface for my entire operating system, and that is the feature I value the most in all of my computing experience.

@ibhagwan
Copy link
Owner

ibhagwan commented Feb 12, 2023

Ty @cpakkala, FYI, some previewers don’t have a “native” equivalent, for example help_tags, that’s not to say it’s impossible, I already added a native previewers for man pages which can be used with :FzfLua man_pages previewer=man_native and I plan to add a similar one to help. added previewer help_native as well.

Lmk if you find other providers where a native previewer is missing and would be desirable and I’ll do my best to add it.

@nyngwang
Copy link
Contributor

nyngwang commented Feb 13, 2023

[...], you can use fzf_colors to change the background color of fzf [...]

@ibhagwan Works :)! One more little question please: how to add a border for the tmux popup like the one in OP?

update: I just resolved the little question by look-up the manual 🫣:

fzf_colors = {
  ['bg'] = { 'bg', 'Normal' },
  ['border'] = { 'fg', 'FloatBorder' },
},
fzf_opts = {
  ['--border'] = 'bold',
},

I just noticed a little problem regarding the background color of fzf: there is a blink of transparent background during the toggling/opening of tmux fzf popup:

tmux-fzf-popup-blink.mov

@ibhagwan
Copy link
Owner

One more little question please: how to add a border for the tmux popup like #225 (comment) in OP?

After engaging in junegunn/fzf#3162, I learned fzf-tmux uses tmux popup -B which is hardcoded to not use any border of the tmux popup, this so you can utilize the fzf border setting, just add --border to fzf:

Can also add this to setup:

:lua require("fzf-lua").files({ fzf_opts = { ["--border"] = "rounded" } })

Border options are (from man fzf):

       --border[=BORDER_OPT]
              Draw border around the finder

              rounded       Border with rounded corners (default)
              sharp         Border with sharp corners
              bold          Border with bold lines
              double        Border with double lines
              horizontal    Horizontal lines above and below the finder
              vertical      Vertical lines on each side of the finder
              top (up)
              bottom (down)
              left
              right
              none

If you wish to color it differently you can use:

:lua require("fzf-lua").files({fzf_bin="fzf-tmux",fzf_opts={["--border"]="rounded"},fzf_colors={["border"
]={"fg","Normal"}}})

Full fzf-tmux setup (accounting for native previewers where possible):

require("fzf-lua").setup({
    fzf_bin = "fzf-tmux",
    fzf_opts = {
      ["--border"] = "sharp",
      ["--no-separator"] = "",
    },
    fzf_colors = {
      ["bg"] = { "bg", "Normal" },
      ["fg"] = { "fg", "Normal" },
      ["border"] = { "fg", "Normal" },
    },
    fzf_tmux_opts = { ["-p"] = "80%,90%" },
    winopts = { preview = { default = "bat" } },
    manpages = { previewer = "man_native" },
    helptags = { previewer = "help_native" },
    tags = { previewer = "bat_async" },
    btags = { previewer = "bat_async" },
})

@ibhagwan
Copy link
Owner

I just noticed a little problem regarding the background color of fzf: there is a blink of transparent background during the toggling/opening of tmux fzf popup:

That's the tmux popup background color appearing right before fzf's --color=border:... takes place, this is controlled by tmux and not fzf-lua, if you wish to avoid the flash of different colors you can set the tmux popup background to the same color, for example:

tmux setw -g popup-style bg=colour2 # terminal green
tmux setw -g popup-style bg=#000000 # RGB black

If you wish to avoid the flash find out the exact RGB color of your neovim colorscheme's Normal color and add the above line to your .tmux.conf (remove the tmux prefix):

setw -g popup-style bg=#000000

@nyngwang
Copy link
Contributor

nyngwang commented Feb 13, 2023

@ibhagwan I have no problem now! Really love the result! Wish you have a nice day!

fzf-lua-tmux-popup-perfect.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature
Projects
None yet
Development

No branches or pull requests

4 participants