Undofile independent of the Vim version

血红的双手。 提交于 2019-12-20 06:31:08

问题


I'm using the Vim 7.3 feature undofile the following way:

if version >= 703
 set undofile
 set undodir=$HOME/.vim/undo
 set undolevels=1000
 set undoreload=10000
endif

I am using the same .vimrc and the same files (within a cloud storage) on different machines which do not support Vim 7.3 but use the old 7.2 version which does not support undofile out of box. Is there a solution for the 7.2 version compatible with the 7.3 undofile?


回答1:


version check

Because persistent undo was introduced with Vim 7.3, your version check is fine, and prevents errors in older Vims. Usually, you would check for the feature itself; :help 'undofile' has this note:

{only when compiled with the |+persistent_undo| feature}

So the correct check (that also handles Vim 7.3 versions that were explicitly compiled without the feature) would be:

:if has('persistent_undo')

persistent undo for Vim 7.2

The reason that persistent undo has been implemented in core Vim is that this would be very difficult or even impossible to do in a plugin. Therefore, I know of no plugin that back-ports this functionality to Vim 7.2; I also don't see any motivation for such an endeavor, because the feature is non-essential and the solution is so simple: just upgrade to the latest Vim. If you have to administrative rights to install Vim on the system, you could compile or copy a user-local installation of Vim into your home directory.



来源:https://stackoverflow.com/questions/16224228/undofile-independent-of-the-vim-version

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