トップ> mac os x> vimのUTF8,EUC,SJIS自動判別
vimのUTF8,EUC,SJIS自動判別
いつも悩む。
すぐ忘れるので「ずんWiki」さんを引用
ずんWikiさんのすばらしい情報そのままです。
ずんWiki
私の環境でははじめを以下のように変更しています。
set encoding=utf-8
set fileencoding=utf-8
" 文字コードの自動認識
if &encoding !=# 'utf-8'
set encoding=japan
set fileencoding=japan
endif
if has('iconv')
let s:enc_euc = 'euc-jp'
let s:enc_jis = 'iso-2022-jp'
" iconvがeucJP-msに対応しているかをチェック
if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'eucjp-ms'
let s:enc_jis = 'iso-2022-jp-3'
" iconvがJISX0213に対応しているかをチェック
elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'euc-jisx0213'
let s:enc_jis = 'iso-2022-jp-3'
endif
" fileencodingsを構築
if &encoding ==# 'utf-8'
let s:fileencodings_default = &fileencodings
let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
let &fileencodings = &fileencodings .','. s:fileencodings_default
unlet s:fileencodings_default
else
let &fileencodings = &fileencodings .','. s:enc_jis
set fileencodings+=utf-8,ucs-2le,ucs-2
if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
set fileencodings+=cp932
set fileencodings-=euc-jp
set fileencodings-=euc-jisx0213
set fileencodings-=eucjp-ms
let &encoding = s:enc_euc
let &fileencoding = s:enc_euc
else
let &fileencodings = &fileencodings .','. s:enc_euc
endif
endif
" 定数を処分
unlet s:enc_euc
unlet s:enc_jis
endif
" UTF-8の□や○でカーソル位置がずれないようにする
if exists("&ambiwidth")
set ambiwidth=double
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
カテゴリ内の記事
- MAC OS X の AirMACってなに?(2005/09/10)
- iBook G4およびPowerBook G4バッテリーリコール(2005/09/13)
- Safariで¥が文字化け(2005/10/01)
- Terminalでの日本語入力(2006/12/02)
- vimのUTF8,EUC,SJIS自動判別(2006/12/02)
- XML::RSS、XML::Parser、Expatで泣いた(2006/12/02)
- consoleからapacheの再起動(2007/02/21)
- MacPortsのインストール(2008/03/15)
- mac os x画面キャプチャ(2009/04/02)
