2

When we call :Gdiff on a file, fugitive will create a buffer with a name fugitive:///path/to/file/. The modifiable option is off and readonly option is on. Most importantly, the file does not exist on the disk so that the function filereadonly(FILENAME) returns false. How to setup such a temporary file?

1
  • I don't think filereadonly() is a Vim function. Did you mean filereadable()?
    – Rich
    Aug 20, 2018 at 11:52

1 Answer 1

4

You can create a buffer like this with the 'buftype' option:

:set buftype=nofile

As :help 'buftype' explains:

The value of this option specifies the type of a buffer:

  <empty>       normal buffer
  nofile        buffer which is not related to a file and will not be
                written

See :help special-buffers for more background on this and other, related, options.

N.B. As far as I can tell, the fugitive plugin doesn't actually set this value of 'buftype' anywhere. It does use buftype=nowrite in a few places but not, for me, in the :Gdiff buffer. (But then, for me, it also doesn't set 'nomodifiable' or 'readonly' as you describe in your question, so possibly you're just using a different version.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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