The Linux Page

Why are my "vim: ..." commands not activated?

I use gVim all the time, I like that editor very much (emacs is just way too much, if you ask me.)

But once in a while I install a new server and by default they generally turn off the modeline feature. This is because there are potential security risks in link with that feature (i.e. vim starts running whatever script is defined in the text files that you edit...)

Anyway, I most often forget about the command to enable my:

vim: <setup>

(I most often define the tab stops, corresponding shift width and eventually the syntax of a file.)

Only, on those new servers, that doesn't work at all. Those details get ignored. This is because modeline is not set.

To set it, what you want to do is edit the (system) vimrc file:

vim /usr/share/vim/vimrc

And add this line to the file:

set modeline

Anywhere will work. As I am at it, I generally put a few other thigs such as:

set modeline ai nowrap hls nocindent incsearch vb sc ru

Although I do not recommand the "ai" (autoindent) if you access that computer only through a console. This is because that doesn't work well when you do a paste with your middle mouse button. In that case, gVim has no clue that you are pasting and it is likely to indent your text improperly. At the same time, not having auto-ident when you edit a file can be particularly annoying.