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: Proper Support for Opening in a New Tab #1785

Closed
1 task done
yavorski opened this issue Feb 2, 2025 · 12 comments
Closed
1 task done

Feature: Proper Support for Opening in a New Tab #1785

yavorski opened this issue Feb 2, 2025 · 12 comments
Labels
feature request New feature

Comments

@yavorski
Copy link

yavorski commented Feb 2, 2025

Have you RTFM'd?

  • I have done proper research

Feature Request

Hi, Not sure if this is a bug or feature request.

Summary

When opening an entry from any fzf-lua picker in a new tab, the current buffer is carried over to the new tab.

This seems to happen because fzf-lua uses tab split instead of tabnew when handling new tabs.

Current Behavior

  • fzf-lua opens new tabs using tab split, which results in the current buffer being present in the newly opened tab.
  • I currently override this behavior for file_picker in my configuration, but it is tedious to do so for all pickers.

Workaround

Here is my current override:

config = function(_, options)
  local A = require("fzf-lua.actions")

  A.file_tabedit = function(selected, opts)
    local vimcmd = "tabnew | <auto>"
    A.vimcmd_entry(vimcmd, selected, opts)
  end

  require("fzf-lua").setup(options)
end

Expected Behavior

  • Opening a file in a new tab should start with just the selected file, without carrying over the current buffer.

Proposed Solution

Would it be possible to replace tab split with tabnew in fzf-lua to solve the issue?

Related Issue

There is also an open issue in the scope.nvim repository regarding this behavior:

tiagovla/scope.nvim#35.

Should this be addressed in fzf-lua instead?

@yavorski yavorski added the feature request New feature label Feb 2, 2025
@phanen
Copy link
Contributor

phanen commented Feb 2, 2025

This way creates No Name buffer each time do file_tabedit...
Maybe that's why tab split is used as default now?

 20  h   "[No Name]"                    line 1
 21  h   "[No Name]"                    line 1
 22  h   "[No Name]"                    line 1
 33  h   "[No Name]"                    line 1
 34  h   "[No Name]"                    line 1
 35  a   "[No Name]"                    line 0
 36  h   "[No Name]"                    line 1

maybe "tabnew +se\ bh=wipe"?

@yavorski
Copy link
Author

yavorski commented Feb 2, 2025

Hmm, it is not creating [no name] buffers for me, neither is tabnew with nvim --clean.

@phanen
Copy link
Contributor

phanen commented Feb 2, 2025

emm... it will

~ master ❯ nvim --clean --headless --cmd 'tabnew | tabnew | tabnew' --cmd 'ls'

  1      "[No Name]"                    line 1
  2  a   "[No Name]"                    line 0
  3 #a   "[No Name]"                    line 0
  4 %a   "[No Name]"                    line 1  

@yavorski
Copy link
Author

yavorski commented Feb 2, 2025

Hmm, but you are not opening any actual files? I guess this is normal since you are just opening an empty new tab?

nvim --clean --headless --cmd 'tabnew readme.md | tabnew .gitignore | tabnew bin.sh' --cmd 'ls!'

  1      "[No Name]"                    line 1
  2  a   "readme.md"                    line 0
  3 #a   ".gitignore"                   line 0
  4 %a   "bin.sh"                       line 1

@phanen
Copy link
Contributor

phanen commented Feb 2, 2025

You're right, but the template used by fzf-lua is tabnew | e <file>:

nvim -n --clean --headless  +'tabnew | e readme.md | tabnew | e .gitignore | tabnew | e bin.sh' +'ls!'

  1  a   "[No Name]"                    line 1
  2  a   "readme.md"                    line 0
  3 #a   ".gitignore"                   line 0
  4 %a   "bin.sh"                       line 1

In some case it can be different (when your buffer have been loaded)

nvim -n --clean --headless --cmd 'e readme.md | e .gitignore | e bin.sh' +'tabnew | e readme.md | tabnew | e .gitignore | tabnew | e | tabnew | e bin.sh' +'ls!'

  1  a   "readme.md"                    line 1
  2  a   ".gitignore"                   line 1
  3 %a   "bin.sh"                       line 1
  4  h   "[No Name]"                    line 1
  5  h   "[No Name]"                    line 1
  6 #h   "[No Name]"                    line 1

@yavorski
Copy link
Author

yavorski commented Feb 3, 2025

Handling the edge cases might be tricky, and solution would likely involve a combination of tab split, tabedit, or tab drop.
I remember this was working fine in Telescope before I switched to fzf-lua, so I guess it should be possible.
Don't have a strong preference on how (or if) this should be solved - just sharing the problem and workaround here.

@ibhagwan
Copy link
Owner

ibhagwan commented Feb 4, 2025

Ty both @Yarovski and @phanen, I’ll do some testing and think about it, I’ve been wanting to refactor the whole thing to use vim.fn.bufadd+bufload+win_set_buf which is a better approach if we want to open a new buffer without first switching into the window (which we must do with :e ….

Since @Yarovski already has a workaround this is no rush so we can think about it for a while.

@yavorski
Copy link
Author

Meanwhile I have added man_tab and help_tab to my configuration since I use them frequently with tabs.
The suggested approach from @phanen to use bh=wipe works well combined with only for man_tab and help_tag.
Not sure how to apply it for the file_tabedit though.

Summary:

  • man_tab - Currently working fine. Didn't notice any issues.
  • help_tab - Currently working fine. Didn't notice any issues.

file_tabedit

  • Creates [no name] buffers when opening a file that is already open (using fzf-lua in a new tab).
  • Has an edge case: if you try to open the currently active buffer in a new tab via fzf-lua, it only opens an empty [no name] buffer instead of the selected entry.

Code:

-- FZF Lua actions
local A = require("fzf-lua.actions")

-- FILES New Tab
A.file_tabedit = function(selected, opts)
  local vimcmd = "tabnew | <auto>"
  A.vimcmd_entry(vimcmd, selected, opts)
end

-- HELP New Tab
A.help_tab = function(selected, opts)
  local topic = selected[1]:match("[^%s]+")
  vim.cmd("tabnew | setlocal bufhidden=wipe | help " .. topic .. " | only")
end

-- MAN Page New Tab
A.man_tab = function (selected)
  -- moving M to the upper scope, breaks `file_tabedit` ?
  local M = require("fzf-lua.providers.manpages")
  local topic = vim.tbl_map(M.manpage_vim_arg, selected)[1]
  vim.cmd("tabnew | setlocal bufhidden=wipe | Man " .. topic .. " | only")
end

These might have more downsides, but I haven't noticed them yet.

@ibhagwan
Copy link
Owner

ibhagwan commented Feb 13, 2025

@yavorski, what I won’t understand is why continuing the current buffer with tab split a problem? Ok, so the tab opens with the current buffer and then we change to the selected file, why is that causing an issue?

@ibhagwan
Copy link
Owner

9dd089f

Since this just affects tab opens I don’t mind the change, fixed the edge cases you mentioned @yavorski.

@yavorski
Copy link
Author

@yavorski, what I won’t understand is why continuing the current buffer with tab split a problem? Ok, so the tab opens with the current buffer and then we change to the selected file, why is that causing an issue?

It's mostly a matter of organization, workflow, and personal preference.
Some users (myself included) prefer to scope certain buffers to tabs to enhance their workflow.

9dd089f

Thanks for the update! Everything works great now.

@ibhagwan
Copy link
Owner

Thanks for the update! Everything works great now.

Great, thanks for the update!

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

3 participants