Vim: read modeline after opening the file?

。_饼干妹妹 提交于 2021-02-07 06:49:35

问题


I work on a variety of projects and many of them set file-specific vim settings. I have been asked to not have modelines set in .vimrc; is there a way after loading the file to load the modelines settings?

So if I open tmp.c with vim:

int main(int argc, char* argv[]) {
    return 0;
}

/* vim: set expandtab tabstop=4 : */

Is there a command I can run to set the stuff in the modeline? Just doing :set modeline after it is open doesn't do anything.


回答1:


After :set modeline, reload your buffer with :e.




回答2:


If you do not want to reload the buffer (e.g. because it contains unpersisted changes, or to avoid clearing the undo history), you can use the fact that a :doautocmd triggers modeline processing:

:set modeline | doautocmd BufRead



回答3:


You can tell vim to execute arbitrary commands before sourcing your ~/.vimrc:

$ vim --cmd "set modeline" yourfile


来源:https://stackoverflow.com/questions/24221294/vim-read-modeline-after-opening-the-file

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