what does "vim:et:ts..." mean in vi?

1,676 views
Skip to first unread message

skyworld

unread,
Jan 5, 2013, 8:33:05 PM1/5/13
to vim_use
Hi,

I'm reading someone's code and at the end of the file I found some
code like this:


#
###########################################################################­
#
#{{{ * Editor configuration
#
###########################################################################­
#
# Local Variables:
# mode: python
# mode: outline-minor
# outline-regexp: " *#{{{ [#*]+"
# indent-tabs-mode: nil
# End:
# vim:et:sw=4:ts=4:ft=python:


I'm interested those "vim:et:sw...." because I'm a user of vi, but I
don't know what these "comments" means and I guess they have some
special usage. Can anybody help me? thanks.

Tim Chase

unread,
Jan 5, 2013, 8:43:27 PM1/5/13
to vim...@googlegroups.com, skyworld
On 01/05/13 19:33, skyworld wrote:
> I'm reading someone's code and at the end of the file I found some
> code like this:

> # vim:et:sw=4:ts=4:ft=python:
>
>
> I'm interested those "vim:et:sw...." because I'm a user of vi, but I
> don't know what these "comments" means and I guess they have some
> special usage.

You want to read at

:help modeline
:help 'modelines'

It allows you to set various options for the file, in case the
file/project happens to override your default settings. In your
example, it sets 'expandtab', 'shiftwidth', 'tabstop', and
'filetype' according to PEP8 standards.

-tim




Tony Mechelynck

unread,
Jan 5, 2013, 8:49:56 PM1/5/13
to vim...@googlegroups.com
On 06/01/13 02:33, skyworld wrote:
> Hi,
>
> I'm reading someone's code and at the end of the file I found some
> code like this:
>
>
> #
> ###########################################################################�
> #
> #{{{ * Editor configuration
> #
> ###########################################################################�
> #
> # Local Variables:
> # mode: python
> # mode: outline-minor
> # outline-regexp: " *#{{{ [#*]+"
> # indent-tabs-mode: nil
> # End:
> # vim:et:sw=4:ts=4:ft=python:
>
>
> I'm interested those "vim:et:sw...." because I'm a user of vi, but I
> don't know what these "comments" means and I guess they have some
> special usage. Can anybody help me? thanks.
>

Short answer: After vim: each colon-separated part is the argument of a
:setlocal command.

Long answer: See (in Vim)
:help modeline
:help 'modeline'
:help 'modelines'

�and read attentively, it is said that "some" forms of modelines are
compatible with "some" versions of (legacy) vi. Or maybe your vi version
has help about them?


Best regards,
Tony.
--
In India, "cold weather" is merely a conventional phrase and has come
into use through the necessity of having some way to distinguish
between weather which will melt a brass door-knob and weather which
will only make it mushy.
-- Mark Twain

Tony Mechelynck

unread,
Jan 5, 2013, 10:29:27 PM1/5/13
to skyworld, Vim List
On 06/01/13 03:25, skyworld wrote:
> Hi Tim & Tony,
>
> thanks for your kind reply. After reading the help, I still have a
> question on this:
>
> the help has two examples on this:
> a) Example:
> vi:noai:sw=3 ts=6
> b) Example:
> /* vim: set ai tw=75: */
> and in my code:
> c) # vim:et:sw=4:ts=4:ft=python:
>
> Since these three examples has different formats at beginning (i.e, /*
> or # or ""), I guess the vim modeline settings should be "put" after
> the comments of the line, and this comment maybe different, e.g, if
> you are using C, it should be put behind /*; and if you are using
> shell/perl/python, it should be put behind "#". And this comment
> should be put at the end of the file. Do I understand this correct?
> thanks.
>
>
> Skyworld

The comment should be put within 'modelines' lines (usually 5 lines) of
the beginning *or* end of the file, your choice. It will only work if
'modeline' (in the singular) is on, which is the default provided that
you're running Vim in 'nocompatible' mode and not in the root (i.e.
sysadmin) login account.

When using C with /* and */, you should use the second form (with "set")
because the other one goes on till the end of the line. Similarly for
HTML or XML with <!-- and -->. In the case of HTML you may prefer to put
the modeline near the top of the file, immediately after the <head>
opening tag. OTOH for C++ or javascript or CSS you can use a // comment
and that needs no closing boundary other than the end of the line, so in
that case a modeline of the first form (with colons and no "set") is
acceptable.

And yes, how the comment is written depends on the programming language:
# in (for instance) a shell script, a double-quote character in a Vim
script, and I gave other examples in the above paragraph.


Best regards,
Tony.
--
If little else, the brain is an educational toy.
-- Tom Robbins

skyworld

unread,
Jan 5, 2013, 10:33:01 PM1/5/13
to vim_use
thanks very much.


skyworld

On Jan 6, 11:29 am, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
>                 -- Tom Robbins- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages