Vim: How to 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 a text width of 60.

I think this can be done for certain types of files using autocmd, but how can I do this for certain files?

+7
source share
2 answers

You can do it like this:

autocmd BufReadPre README*.txt setlocal textwidth=60 

Or you can list files one at a time:

 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 the buffers to have this text width for the entire session.

+6
source

You can also add a comment at the beginning of the file:

 # vim: textwidth=80 

You can replace # with any character meaning a comment in your context.

+6
source

All Articles