how to specify indentation for a file?
I heard that we can specify VIM indent for a file by embedding the indentation commands into the file to be edited.
Can 开发者_如何转开发somebody let me know how to do this?
The thing you are looking for is called a modeline.
Here is a modeline that I commonly use for vim:
/* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: */
A similar thing for emacs would look like this:
/* -*- Mode: tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
This question has been covered before though.
Something like
// vim: set ts=4 sw=4 et:
where //
is your language's comment marker.
You can also specify indentation for a given filetype.
For example for python files, you can add this line to your .vimrc file:
autocmd FileType python set sw=4 sta
The advantage compared to modelines is that you don't have to write it everytime. Then for a specific python file, if you want to change the indentation, you can write this modeline:
# vim: set sw=2:
精彩评论