2

I have a funny problem.

I have the following symlink in /Users/eyalkarni/ AKA ~

.vimrc -> /Users/eyalkarni/vimpy3/.vimrc

vimpy3 is a git repository.

I opened ~/.vimrc in neovim and now I can't use git-fugitive because it doesn't know it is inside git repo.

So, naturally, I tried :bd and going into ~/vimpy3 and open it from there.

It didn't work either. It keeps calling it ~/.vimrc , thinking it is in ~.

I guess :bw will work, but I also have some marks in the file that I don't want to lose.

How to overcome this?

  • I thought about going to the cache file of neovim (where it keeps the marks) and changing the name of the buffer. Couldn't find it. – eyal karni Aug 17 '19 at 22:37
  • 3
    Check :h :0file and :h :file_f – klaus Aug 18 '19 at 6:47
  • You can post this as an answer – eyal karni Aug 18 '19 at 11:24
  • 1
    I didn't post it as answer cz I don't know if it will work. Vim-fugitive might only initialize when you open a file, and in that case, changing the filename isn't gonna do you any favor. I just wanted you to know that there is a process to change the filename associated with the current buffer. If the process worked, you can post an answer yourself; or let me know that it worked and I'll post the answer. – klaus Aug 18 '19 at 15:22
  • 2
    It worked. Just had to do :file using the full path and then e to reload. – eyal karni Aug 18 '19 at 15:25
2

I don't know how vim-fugitive checks if the current file is under a git repository, but for this specific case you can follow the following steps to get the job done:

:file <path/to/file>
:edit

Here, :file <path/to/file> changes the associated file of the current buffer to the provided file and :edit reloads the current buffer. A buffer is the in-memory text of a file. So, what you see on the window/split is actually a buffered memory (hence the name buffer). When you do :write, you save the current buffered memory to the associated file and when you do :edit, you reload the current buffered memory with the content of the associated file. So, when you do :file <path/to/file> you change the associated file of the current buffer and henceforward do any interaction with that file.

Now, when you changed the associated file and reloaded it, the buffer checked that it's in a git repository and launched vim-fugitive instance; or so I conjecture since I already got the confirmation that this solution worked from the OP.

Check out :h file_f for more information.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.