Vimscript check if current buffer has unsaved changes

廉价感情. 提交于 2019-12-21 03:35:17

问题


I currently have my status line set up so that it's orange in insert mode and white otherwise. I'd like to make it go another color when I drop back to normal mode if the file has any unsaved changes, as I regularly take a little walk down a rabbit hole wondering why my changes have not taken effect. The little "[+]" doesn't smack me in the face enough ;)

I can't find any functions that start with "buf" and look like predicates for dirtiness though. I assume one exists, but is named something else. I expect there to be something like bufdirty() or bufchanged(). Any pointers? :)


回答1:


I think that you are looking for

:echo &mod[ified]

which returns 1 if modified and 0 if not modified.




回答2:


I like the idea of using the statusline color to indicate the buffer state. In fact, I've written the StatusLineHighlight plugin, which indicates the following attributes: modified, readonly, unmodifiable, special non-file "scratch" (but not the insert mode that you're using; for that, I find Vim's mode indication in the lower left corner enough).



来源:https://stackoverflow.com/questions/13107453/vimscript-check-if-current-buffer-has-unsaved-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!