VIM putting a line at the top (or bottom) of a tile to set attributes? doesnt work for me
I read in "Vim book OPL.pdf" that you can put a l开发者_如何学Goine at the top of a file, say for instance a .txt file and it would change how that individual file was handled by Vim. for example vim:tw=78
however it doesnt do anything for me and I am wondering if this is still the case for vim7.0 ?
It is called a "modeline" and you can get more information by typing:
:help modeline
From the description in help, I think the correct format should be vim: tw=78
It seems your example is missing white spaces.
Addition from elwoode comment :
Adding the modeline won't reformat automatically existing text. If you want to reformat you have to select an area and use gq
. See :help gq
To reformat the whole file according to modeline, use:
gggqG
(gg
means go to first line, gq
apply formating to motion, G
go to last line)
Be sure that in .vimrc you have formatoptions+=t
to take into account formatting according to textwidth. It seems that on my installation t
is part of the default formatoptions
.
The modeline is often disabled by default due to security reasons (the last of which are abolished in Vim 7.3 as I understand it); it is in Debian, for example. It will be in your case (see :set modeline?
).
Add set modeline
to your vimrc if you wish to enable modeline support.
You're trying to set a modeline.
Syntax would be:
vim:set textwidth=78:
Just an option, you can use your .vimrc if you want:
autocmd FileType .txt set textwidth=78
精彩评论