Vim Tips Wiki
No edit summary
No edit summary
Line 5: Line 5:
 
|created=June 5, 2010
 
|created=June 5, 2010
 
|complexity=basic
 
|complexity=basic
|author=dnlcorrea
+
|author=Dnlcorrea
 
|version=7.0
 
|version=7.0
 
|subpage=/201006
 
|subpage=/201006

Revision as of 13:03, 17 June 2010

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created June 5, 2010 · complexity basic · author Dnlcorrea · version 7.0

If you save a file using Vim or MacVim and try to open it with Quicklook, the characters will not display correctly. That is because Mac OS uses an extended attribute to determine the encoding of a file.

To fix, add this to your vimrc:

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 in double quotes to escape spaces for the shell. The :silent command prevents Vim from displaying the results (which are empty).

If you want this for .txt files only, use the following instead:

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

Using the command ls -l will show '@' in the file's attributes, for example:

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

Comments