Vim Tips Wiki
(Insert TipProposed template + minor manual clean)
m (fix broken tag)
Line 16: Line 16:
 
<pre>
 
<pre>
 
au BufWritePost * :silent !xattr -w com.apple.TextEncoding 'UTF-8;134217984' "%"
 
au BufWritePost * :silent !xattr -w com.apple.TextEncoding 'UTF-8;134217984' "%"
<pre>
+
</pre>
   
 
This will append the extended attribute in every file you save. Note that <tt>%</tt> is in double quotes to escape spaces for the shell. The <tt>:silent</tt> command prevents Vim from displaying the results (which are empty).
 
This will append the extended attribute in every file you save. Note that <tt>%</tt> is in double quotes to escape spaces for the shell. The <tt>:silent</tt> command prevents Vim from displaying the results (which are empty).

Revision as of 08:26, 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 · 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