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

When opening a new file using neovim-fuzzy the cwd for the "current" tab is changed to the git root #46

Open
insidewhy opened this issue Nov 25, 2019 · 4 comments

Comments

@insidewhy
Copy link
Contributor

insidewhy commented Nov 25, 2019

This happens when fuzzy_opencmd is set to tabe (or tab drop or any other command that opens the result in a new tab).

e.g. say I am in a project called project inside subdirectory subdir which contains two files, file1 and file2.

When I open the first file with neovim-fuzzy, say file1 then the file1 tab corrrectly has project/subdir as its cwd. Now if I open a second file while the file1 tab is focussed, say file2 then the new tab with file2 in it has the correct cwd of project/subdir but the file1 tab now has a cwd of project.

Then if I were to open a third file with neovim-fuzzy, while looking at the file2 tab, now that tab will also have a cwd of the project root. It always sets the cwd of the "current" tab to the project root.

@insidewhy
Copy link
Contributor Author

BTW tested this with neovim-fuzzy as the only plugin enabled, and it still happened.

@insidewhy
Copy link
Contributor Author

insidewhy commented Nov 25, 2019

Here is my workaround:

fun s:FuzzyOpener(val)
  let prev_tabpage = tabpagenr()
  exe "tabe" a:val
  let next_tabpage = tabpagenr()
  exe "tabnext" prev_tabpage
  lcd -
  let dir = getcwd()
  exe "tabnext" next_tabpage
  exe "lcd" dir
  " neovim-fuzzy will execute "lcd -" so ensure the previous directory is the
  " one we want
  lcd /tmp
endfun

command! -nargs=1 FuzzyOpener call s:FuzzyOpener(<q-args>)

let g:fuzzy_opencmd = 'FuzzyOpener'  

It is dirty but it works.

@insidewhy insidewhy changed the title When opening a new file using neovim-fuzzy the cwd is changed for the current tab to the git root When opening a new file using neovim-fuzzy the cwd for the "current" tab is changed to the git root Nov 25, 2019
@insidewhy
Copy link
Contributor Author

The correct fix would be to change this bit of code:

It would have to store the current tab before running the open command, and then check if the tab has changed. When it has, then it should switch to the previous tab and run lcd to the directory of the new tab, before switching back to the new tab.

@insidewhy
Copy link
Contributor Author

Or alternatively it could just not lcd at all and instead resolve the path to open with respect to self.root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant