Given a buffer number i
, I want to check if the buffer has been modified after the last save. How do I do that in vimscript?
I tried to use getbufvar()
like the following:
if getbufvar(i, "&modified")
echo "Modified"
else
echo "Not Modified"
endif
but this always seems to echo
"Modified". What am I doing wrong?
getbufvar(bufnr, '&mod')
fails to work in your case. Are you sure you're using the right buffer id? For instance, in some autocommand cases, it's easy to get confused and use'%'
instead of<amatch>
getbufvar(expand('<abuf>'), ...)
.