Vim Tips Wiki

Display UTF-8 characters in Mac Quicklook

1,623pages on
this wiki
Add New Page
Add New Page Talk0
Tip 1654 Printable Monobook Previous Next

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 * :if &fenc=='utf-8' || (&fenc=='' && &enc=='utf-8') | exec "silent !xattr -w 'UTF-8;134217984' \"%\"" | endif

This will append the extended attribute in every file you save with a UTF-8. 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 :if &fenc=='utf-8' || (&fenc=='' && &enc=='utf-8') | exec "silent !xattr -w 'UTF-8;134217984' \"%\"" | endif

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



  • Use shellquote instead of surrounding with spaces manually?
  • explain the 134... number. What the heck is it for?

Also on Fandom

Random Wiki