Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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?

like image 821
FunLovinCoder Avatar asked Nov 05 '12 11:11

FunLovinCoder


2 Answers

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.

like image 134
Benj Avatar answered Nov 16 '22 17:11

Benj


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.

like image 39
mpenkov Avatar answered Nov 16 '22 19:11

mpenkov