Background: I am doing more and more stuff directly from inside Neovim, and less and less from the terminal or even the terminal emulator. So instead of going to the desired directory to work in, and then starting Neovim, I prefer to just start Neovim, and then change to the desired directory. This next part is a bit of a tangent so you can skip to the next paragrapah if you just want the important details, but I know people tend to want to know why I am doing things a certain way so they can potentially suggest a better way. I do this because I will often need to change to different directories anyway multiple times at different points after I start working in Neovim. This way I don't have to close Neovim and open it again from another directory, or else start another instance of Neovim and then not be able to yank and put between them and have to keep track of which running Neovim instance is for what. In order to make it easier to work with a single Neovim instance and change directories, I do 2 things. I have NERDTree setup so that changing the current working directory in Neovim also changes the tree root in NERDTree, and vice versa. I also create commands to quickly navigate to different commonly used directores. Think of these like aliases. These all start with
:C. For example if I want to work on my vim-project-tags plugin, I enter the command
:Cproj and this will change to the directory where that code is.
Problem: When I first start Neovim, the current buffer is not pointed at any file. If I run the vim-fugitive command
:G this only works if the directory I started Neovim in has a git repository. So far this is fine. The problem comes in when I then change to a different working directory from inside Neovim, and then run the
:G command. At this point, the command is still associated with the directory I started Neovim in, not the current working directory. This works the same way in regular Vim. It doesn't matter to me at this point if I previously had a buffer open to a certain file and this still exists or not. I still want fugitive to use the current working directory even in that case. I'm not saying I want fugitive to become working directory based in stead of buffer based. I'm saying I want it to use the last changed of the two, either I opened a buffer to a different file, or I changed the working directory.
Question: How do I get vim-fugitive to base its commands on the current working directory when the current buffer is not pointed at a file?
Further Thoughts: I know I could just start editing a file from that project, and then vim-fugitive will know which repository to work with. But that is precisely what I am trying to avoid. For me, one of the main appeals of Vim/Neovim is you can do micro-optimizations for everything about your workflow. I don't want to have to change to the correct directory and open a file from it before I can work with vim-fugitive because it is less steps to just change to that directory and then start working with it. I realize that I could accomplish this in the same number of steps by somehow opening the desired file without changing to that directory first, and then working with vim-fugitive, but that would be harder to accomplish and less useful for me. It is easier to edit the files of choice when the current working directory is the project root directory, and this makes working with that project much easier in lots of ways. Alternatively, I could make the command/alias I use to change to the directory of choice also open some kind of default/index file for that project in addition to changing to that directory, but that is not ideal for me. I would have to decide which file is the default/index file for each project. Having it automatically open that file would typically be mentally distracting and then I would have one more buffer I need to delete at some point if I don't want to work with it. Also, there would be times that I change to the directory of choice in a different way, such as navigating around with NERDTree.