Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: read modeline after opening the file?

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.

like image 760
Levi Morrison Avatar asked Jun 14 '14 15:06

Levi Morrison


3 Answers

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

like image 101
gniourf_gniourf Avatar answered Nov 18 '22 23:11

gniourf_gniourf


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
like image 11
Ingo Karkat Avatar answered Nov 18 '22 22:11

Ingo Karkat


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

$ vim --cmd "set modeline" yourfile
like image 3
romainl Avatar answered Nov 18 '22 23:11

romainl