FunLovinCoder
FunLovinCoder

Reputation: 7867

Vim: How do I automatically set textwidth=60 when editing a specific file?

In my .vimrc I have the following line:

set textwidth=80

However, when editing the files: README-SETUP and README-INSTALL I would like vim to have textwidth set to 60.

I think this can be done for specific file types using autocmd, but how would I do it for specific files?

Upvotes: 7

Views: 1171

Answers (2)

mpenkov
mpenkov

Reputation: 21896

You can also add a comment to the top of the file:

# vim: textwidth=80

You can replace the # by whatever character signifies a comment in your context.

Upvotes: 7

Benj
Benj

Reputation: 32398

You could do this like so:

autocmd BufReadPre README*.txt setlocal textwidth=60

Or you could list the files one by one:

autocmd BufReadPre README-SETUP setlocal textwidth=60
autocmd BufReadPre README-INSTALL setlocal textwidth=60

EDIT: As ZyX points out, prefer setlocal over set for options like this you really don't want all buffers having that textwidth for the duration of the session.

Upvotes: 7

Related Questions