Skip to content

Bug: file_tabedit opens file in the wrong directory #1854

@kheaactua

Description

@kheaactua

RTFM Checklist

  • I have searched exisiting issues / discussions
  • I have read the Wiki including the Advanced section
  • I have read man fzf / I am well versed in shell fzf

Operating system

Linux

Shell

zsh

Neovim version (nvim --version)

v0.11.0-dev-1649+gc47496791a

Fzf version (fzf --version)

0.60.2 (c0d407f7)

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

  • My issue is reproducible with mini.sh
  • My issue IS NOT reproducible with mini.sh
  • I have not tested with mini.sh (not relevant, requires LSP, Windows, etc)

Fzf-lua configuration

require("fzf-lua").setup({
        actions = {
          files = {
            ["default"]     = actions.file_edit_or_qf,
            ["ctrl-x"]      = actions.file_split,
            ["ctrl-v"]      = actions.file_vsplit,
            ["ctrl-t"]      = actions.file_tabedit,
            -- ["ctrl-t"]      = file_tabedit_with_cwd,
            -- ["alt-q"]       = actions.file_sel_to_qf, -- dunno what this does
            -- ["alt-l"]       = actions.file_sel_to_ll, -- dunno what this does
            ["ctrl-l"]      = require'fzf-lua.actions'.arg_add, -- dunno what this does
          },
          buffers = {
            ["default"]     = actions.buf_edit,
            ["ctrl-x"]      = actions.buf_split,
            ["ctrl-v"]      = actions.buf_vsplit,
            ["ctrl-t"]      = actions.buf_tabedit,
          }
        },
        buffers = {
          actions = {
            ["ctrl-x"] = actions.buf_split,
            ["ctrl-d"] = actions.buf_del,
          }
        },
        tabs = {
          actions = {
            ["ctrl-x"] = actions.buf_split,
            ["ctrl-d"] = actions.buf_del,
          }
        },
        -- See https://github.com/ibhagwan/fzf-lua/wiki#can-i-use-ripgreps---globiglob-option-with-live_grep
        grep = {
          rg_glob = true
        }
      })

      -- Set up keyboard shortbuts for fzf, the fuzzy finder
      -- This one searches all the files in the current git repo:
      map('n', '<c-k>', '<cmd>lua require("fzf-lua").git_files()<CR>', { silent = true })
      map('n', '<leader>h', '<cmd>lua require("fzf-lua").oldfiles()<CR>', { silent = true })
      map('n', '<leader>t', '<cmd>lua require("fzf-lua").tabs()<CR>', { silent = true })
      map('n', '<leader><Tab>', '<cmd>lua require("fzf-lua").buffers()<CR>', { silent = true })

      -- Unmap center/<CR> from launching fzf which appears to be mapped by default.
      -- unmap <CR>

      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").grep_project()<CR>', { silent = true, debug = true })
      map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep()<CR>', { silent = true })
      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").grep_project({ rg_opts = "--glob \'!**/unittest*/**\'", debug = True })<CR>', { silent = true })
      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep({ rg_opts = "--glob \'!**/unittest*/**\'", debug = True })<CR>', { silent = true })

      -- map('n', '<leader>g', '<cmd>lua require("fzf-lua").live_grep()<CR>', { silent = true })

      vim.keymap.set("n", "gsiw",
        function()
          local fzf_lua = require("fzf-lua")
          local current_word = vim.api.nvim_command_output([[ echo expand('<cword>') ]])
          fzf_lua.live_grep({
            cmd = grep_cmd,
            query = current_word,
            cwd = fzf_lua.path.git_root(),
          })
        end,
        { silent = true }
      )

      map('n', '<leader>l', '<cmd>lua require("fzf-lua").lines()<CR>', { silent = true })
      -- map('n', '<leader>w', '<cmd>lua require("fzf-lua").Windows()<CR>', { silent = true })

   end,

Describe the bug / steps to reproduce

Sometime in the last few weeks, actions.file_tabedit has stopped working. Now when I hit ctrl-tab, it opens a new tab for the file but at the wrong directory.

e.g. If I'm editing a file, I can see with echo getcwd() that I'm at /path/to/base/path/to/project. Say I attempt to open include/file.hpp with ctrl-t (file_tabedit), it SHOULD open:

/path/to/base/path/to/project/include/file.hpp

But instead it opens:

/path/to/base/include/file.hpp

which doesn't exist.

file_split and file_vsplit and work as expected, it's only file_tabedit that stopped working.

Steps to reproduce

  1. Use fzf-lua at a commit that includes 9dd089f
  2. Open nvim in /path/to/base
  3. Somehow open a file deeper in the path, i.e. /path/to/base/path/to/project/include/file.hpp. Use tcd to set your current directory to to /path/to/base/path/to/project. - I think tcd is correct, in my case I use nvim-rooter to handle this, as in this example /path/to/base/path/to/project would be a git repo
  4. Attempt to open another file in this git repo using fzf-lua using the file_tabedit actions

Speculation

I assume it's related to 9dd089f changing from tab split to tabnew. When I jump back to 562593a the function works as expected.

I use nvim-rooter as well to set my path as my work is spread through many different git repos. Perhaps it's only setting the tab's cwd, and tabnew creates a tab with the original cwd? Just speculating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions