telescope-project.nvim icon indicating copy to clipboard operation
telescope-project.nvim copied to clipboard

Feature Request: Equivalent of `:lcd path_to_project` and "no(l)cd" (improve documentation)

Open matu3ba opened this issue 3 years ago • 7 comments

  1. The behavior of how cwd is changed is underspecified. Neovim offers 1. :cd and 2. :lcd to change paths. But one could also think of 3. not changing the path for only opening the file [ie to compare stuff].
  2. I think even changing the default to :lcd would be more optimal, to run things in the script or :e pathtofile on the correct project folder

use cases

  • My simple project for using associated script folders I am frequently looking and copy your code to modify it. Having PATH cluttered makes this annoying for quick lookups.
  • My project intends to make script running usable from the git root of the project. Its very unnatural to have cwd not being set to the project git root, when one wants to run quick scripts or modifies stuff etc.
  • In future I want to make PATH navigation possible (in neovim and shell associated to project) to get restricted to a local project scope. Having correct cwd set is a basic building block for that.

I have also some other remarks on the structure of the project to make re-usage simpler, but this is not imminent. Thanks for the plugin and let me know what you think on this.

matu3ba avatar Aug 12 '21 10:08 matu3ba

yeah, I think it's better to add option to choose between cd, lcd, tcd and no cd

I don't like that plugin cd whole nvim to selected folder

l4zygreed avatar Oct 11 '21 22:10 l4zygreed

I also wanted something like lcd but for a buffer scope instead of a window scope. Just an idea:

local M = {}
local history = {}

vim.api.nvim_exec(
    [[
      augroup TrackCWD
        autocmd!
        autocmd BufEnter * lua require"thisfilepath".on_enter()
        autocmd BufLeave * lua require"thisfilepath".on_leave()
      augroup end
    ]],
    false
)

function M.on_enter()
    local buf = vim.api.nvim_get_current_buf()

    if not vim.api.nvim_buf_get_option(buf, "buflisted") then
        return
    end

    local last_path = history[buf]
    if last_path then
        vim.fn.execute("cd " .. last_path, "silent")
        -- require("nvim-tree").change_dir(last_path) --update nvimtree
    end
end

function M.on_leave()
    local buf = vim.api.nvim_get_current_buf()

    if not vim.api.nvim_buf_get_option(buf, "buflisted") then
        return
    end

    history[buf] =  vim.fn.getcwd(-1, -1)
end

return M

tiagovla avatar Oct 24 '21 23:10 tiagovla

buffer scope instead of a window scope

Please try to explain your use case in harpoon, since the plugin is more tailored to buffer navigation. Project stuff is more logical to do inside windows to have a static reference point (by setting the cwd).

Ideally even fixing the buffers "to have a link" to the window path, so that cwd is set accordingly upon switching to them.

matu3ba avatar Nov 11 '21 10:11 matu3ba

+1 for having an option to choose between :cd and :lcd, I like to have one tab per project and using cd when switching to another project in a new tab messes up the paths in all other project tabs.

maxmahlke avatar Jan 14 '22 10:01 maxmahlke

still no updates to this issue? seems like it's time to learn lua

l4zygreed avatar Apr 09 '22 16:04 l4zygreed

changing this line here to lcd works for me for the time being

rizkifuad avatar May 31 '22 01:05 rizkifuad

Check MR #103 which resolves this at least for me

ccakes avatar Jun 18 '22 04:06 ccakes

Any progress on this? Does the suggested PR solve the problem? It's really annoying that it changes the global cwd and not just the buffer cwd or tab cwd if you choose to open the file in a new tab. Also could we stop the behavior by just selecting the project to also change cwd. Many times I may cancel the command but cwd is already changed. Preferably it could change after selecting a file to open?

dpetka2001 avatar Apr 30 '23 08:04 dpetka2001

Thanks @l4zygreed for resolving this

claidler avatar Dec 01 '23 21:12 claidler