Closed mcepl closed 2 years ago
It seems you can use the nullglob
option or the equivalent for your shell, which I think makes more sense than trying to get vis
to detect it. Also, the heuristic you mention seems unnecessary and unintuitive. I sometimes save empty files and there's nothing wrong with that.
It seems you can use the
nullglob
option or the equivalent for your shell, which I think makes more sense than trying to getvis
to detect it.
OK, I didn't know that. I will try it.
I sometimes save empty files and there's nothing wrong with that.
Yes, but then you run :w
explicitly, it is not just because you pressed ZZ
on empty buffer.
ZZ
effectively means "save and exit" so it is explicitly saving the empty buffer. In this case, I think what you're looking for is ZQ
, which will not save the file.
Take a look at the source code:
https://github.com/martanne/vis/blob/1a958f221404b09cb8b0612fb34301e6b9783cf9/config.def.h#L231
https://github.com/martanne/vis/blob/1a958f221404b09cb8b0612fb34301e6b9783cf9/config.def.h#L234
@martanne I guess, it really doesn't matter what we write here. What do you think? Making vis more for mere humans (and Zenclavier) or keeping vis just a platonic idea without regards to its usefulness for mere humans?
You could also remap ZZ
to a lua function which will drop empty files, actually, as easily as adding the following to your visrc:
vis:map(vis.modes.NORMAL, "ZZ", function()
if vis.win.file.size == 0 then
vis:command(':q!')
else
vis:command(':wq')
end
end)
Also I'm a mere human and using vis.
I think the way Vim does it is ZZ only writes if the buffer has been modified, which would also work in this case (also would be a more sensible option than a special case for empty files).
Hm that does make more sense... that could be default behaviour, here, too.
vis:map(vis.modes.NORMAL, "ZZ", function()
if vis.win.file.modified then
vis:command(':wq')
else
vis:command(':q!')
end
end)
vis:map(vis.modes.NORMAL, "ZZ", function() if vis.win.file.modified then
Wouldn’t this be true even if undo my changes or delete them afterwards? file_size==0
seems like more foolproof solution.
If you want to emulate Vim behavior, this has nothing to do with the size of the file. In Vim, ZZ
is equivalent to :x
, which acts like :wq
if the buffer is modified and :q
if the buffer is not. Anyway, if you were to originally have a file with contents, and then delete the file contents, and then choose to save that file, what logically would follow is an empty file.
Quite often I use command
vis *.spec
(my primary work is with RPM SPEC files), and too often I run this command in a wrong directory. The result is that I have all over the system files called*.spec
and*.changes
(with asterisks in the filename) with zero length.Would it be possible to add to vis a herusitics that it will never CREATE new ZERO-LENGTH file? I can hardly imagine a situation where using
$EDITOR
for creating zero-length files would be preferable totouch filename
orcat /dev/null >filename
.