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 Answer
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.)
filereadonly()
is a Vim function. Did you meanfilereadable()
?