Skip to content

Reuse tabs and windows if buffer already open #3466

Open
@svartkanin

Description

@svartkanin

Description

I have stumbled upon this issue #2188 which seems to be resolved and should provide what I was looking for but I'm facing some issues with reusing open windows and tabs.

I have nvim-neo-tree/neo-tree.nvim and romgrk/barbar.nvim installed as well (not sure if they interfere somehow.

Neovim version

$ nvim --version
NVIM v0.11.1
Build type: RelWithDebInfo
LuaJIT 2.1.1741730670
Run "nvim -V1 -v" for more info

Operating system and version

Archlinux

Telescope version / branch / rev

master (50b5b06)

checkhealth telescope

==============================================================================
telescope:                                 require("telescope.health").check()

Checking for required plugins ~
- ✅ OK plenary installed.
- ✅ OK nvim-treesitter installed.

Checking external dependencies ~
- ✅ OK rg: found ripgrep 14.1.1
- ✅ OK fd: found fd 10.2.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- ✅ OK lib working as expected
- ✅ OK file_sorter correctly configured
- ✅ OK generic_sorter correctly configured

Telescope Extension: `git_worktree` ~
- No healthcheck provided

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

Scenarios

Correct

Current state
neo-tree win_1 win_2
(Tree) buf_1 (focused) buf_2

Run :Telescope find_files and selecting the file from buf_2 it correctly focuses on win_2.

After state
neo-tree win_1 win_2
(Tree) buf_1 buf_2 (focused)

Correct behaviour

Issue 1

Current state
neo-tree win_1 win_2
(Tree) buf_1 (focused) buf_2

Run :Telescope find_files and select a file that is not open yet in a tab or buffer

After State
win_1
buf_3 (focused)
  • It closed neo-tree
  • It closed the second open window
  • It displays the selected file in win_1
Expected state
neo-tree win_1 win_2
(Tree) buf_3 (focused) buf_2

Issue 2

Current state
neo-tree win_1 win_2
(Tree) buf_1 (focused) buf_2

There's also buf_3 open in a remaining tab in the tabline (from barbar.nvim)

Run :Telescope find_files and select the file in buf_3

After state
neo-tree win_1 win_2
(Tree) buf_1 buf_3 (focused)
  • The focused jumped to win_2 and displays buf_3
Expected
neo-tree win_1 win_2
(Tree) buf_3 (focused) buf_2

Expected behavior

No response

Actual behavior

Described above

Minimal config

local actions = require 'telescope.actions'

require('telescope').setup {
  defaults = {
    color_devicons = true,
    mappings = {
      n = {
        ['<CR>'] = actions.select_default + actions.center,
      },
    },
  },
  extensions = {
    ['ui-select'] = {
      require('telescope.themes').get_dropdown(),
    },
  },
  pickers = {
    buffers = {
      mappings = {
        i = {
          -- switch to the open tab or window rather than
          -- replace the buffer in the current one
          ['<CR>'] = actions.select_tab_drop,
        },
      },
      ignore_current_buffer = true,
      show_all_buffers = true,
      sort_last_used = true,
    },
    find_files = {
      find_command = { 'rg', '--one-file-system', '--files', '--iglob', '!.git', '--hidden' },
      mappings = {
        i = { ['<CR>'] = actions.select_tab_drop },
      },
    },
    grep_string = {
      additional_args = { '--one-file-system', '--iglob', '!.git', '--hidden' },
      mappings = {
        i = { ['<CR>'] = actions.select_tab_drop },
      },
    },
    live_grep = {
      additional_args = { '--one-file-system', '--iglob', '!.git', '--hidden' },
      mappings = {
        i = { ['<CR>'] = actions.select_tab_drop },
      },
    },
  },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions