Vim Tips Wiki
Advertisement

If you save a file using Vim or MacVimWhen and try to open it with Quicklook, the characters won't display right. This is because Mac OS uses an extended attribute to determine the encode of a file.

Just add this in your .gvimrc:

au BufWritePost * :silent !xattr -w com.apple.TextEncoding 'UTF-8;134217984' "%"

This will append the extended attribute in every file you save. Note that <%> is between <">, for escaping spaces in the shell. The :silent command prevents vim from printing the results (which are empty) and annoy you.

If you want this for .txt files only, you could do

au BufWritePost txt :silent !xattr -w com.apple.TextEncoding 'UTF-8;134217984' "%"

If you do a `ls -l`, you'll notice the '@' in the file's attributes:

-rw-r--r--@ 1 daniel staff 15 Jun 5 10:12 lol.txt

--Dnlcorrea 16:05, June 5, 2010 (UTC)--Dnlcorrea 14:03, June 5, 2010 (UTC)

Advertisement