Posts Tagged ‘Emacs’
VIM modelines
By chys on February 22nd, 2009I was wondering why all Emacs modeline samples I found online worked so well, but no VIM ones worked at all. In fact, VIM by default disables modelines because it is a potential security hole. (This is too bad. They can enable only safe instructions by default.) Add set modeline to ~/.vimrc to enable it.
A modeline is some instructions to the editor put in the comments, usually in the beginning of a text file. The most common use is probably to set the syntax highlighting rule, tab width and indent.
Modeline example:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ft=cpp ts=2 sw=2 sts=2 cindent: */
The first line is for Emacs and the second for VIM. Note that an Emacs modeline must appear in the beginning of a file, while VIM modelines can be put anywhere.
Basicly, these two lines force the file type to be C++ (especially useful for .h files, which are by default treated as C sources), set the width of a tab to be 2 characters and enable auto indention. (My knowledge about Emacs is very limited, so probably this is not accurate.)
Some resources:
1. GNU Emacs modeline documentation
2. VIM modeline documentation
