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

Is there any options for change the searching directory when the command cd is used? #2964

Closed
shayaniox opened this issue Feb 29, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@shayaniox
Copy link

shayaniox commented Feb 29, 2024

Is your feature request related to a problem? Please describe.
I use cd command but telescope still searches in the directory I opened up.

Describe the solution you'd like
I need telescope to change the base searching directory after changing the directory by cd (and confirmed by pwd).

Describe alternatives you've considered
I've just found the option cwd for the find_files and grep, but it's tedious to modify this option for all the possible functionalities.

@shayaniox shayaniox added the enhancement Enhancement to performance, inner workings or existent features label Feb 29, 2024
@jamestrew
Copy link
Contributor

What do you mean cwd command?

Telescope sets the cwd option for Telescope to the cwd vim.loop.cwd() if the option is not explicitly set.
So if you open nvim in a/ but you :cd b/ then do :Telescope find_files, Telescope will use cwd=b/.

@shayaniox
Copy link
Author

@jamestrew I have the following mapping:

vim.keymap.set("n", "<leader>cc", ":exec 'cd' . expand('%:p:h')<CR>", { noremap = true, silent = true })

According to your comment, the find_files subcommand should search in the new directory, but it doesn't.

@shayaniox shayaniox changed the title Is there any options for change the searching directory when the command cwd is used? Is there any options for change the searching directory when the command cd is used? Mar 6, 2024
@jamestrew
Copy link
Contributor

jamestrew commented Mar 7, 2024

I'm not able to reproduce your claim with this minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons",
    },
    config = function()
      require("telescope").setup({})
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.keymap.set("n", "<leader>cc", ":exec 'cd' . expand('%:p:h')<CR>", { noremap = true, silent = true })
telescope-cd-repo.mp4

I opened a file in a subdirectory and used your <leader>cc bind to change the cwd and afterward I don't see the min.lua file in the original cwd (the parent of the new cwd).

Can you try with this minimal config?

@jamestrew jamestrew added bug Something isn't working and removed enhancement Enhancement to performance, inner workings or existent features labels Mar 7, 2024
@jamestrew
Copy link
Contributor

Closing due to lack of response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants