" See: " https://raw.githubusercontent.com/Shougo/shougo-s-github/master/vim/rc/encoding.rc.vim " The automatic recognition of the character code. " Setting of the encoding to use for a save and reading. " Make it normal in UTF-8 in Unix. if has('vim_starting') set encoding=utf-8 endif " Setting of terminal encoding."{{{ if !has('gui_running') if &term ==# 'win32' && \ (v:version < 703 || (v:version == 703 && has('patch814'))) " Setting when use the non-GUI Japanese console. " Garbled unless set this. set termencoding=cp932 " Japanese input changes itself unless set this. Be careful because the " automatic recognition of the character code is not possible! set encoding=japan else if $ENV_ACCESS ==# 'linux' set termencoding=euc-jp elseif $ENV_ACCESS ==# 'colinux' set termencoding=utf-8 else " fallback set termencoding= " same as 'encoding' endif endif elseif IsWindows() " For system. set termencoding=cp932 endif " }}} " The automatic recognition of the character code."{{{ if !exists('did_encoding_settings') && has('iconv') let s:enc_euc = 'euc-jp' let s:enc_jis = 'iso-2022-jp' " Does iconv support JIS X 0213? if iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb" let s:enc_euc = 'euc-jisx0213,euc-jp' let s:enc_jis = 'iso-2022-jp-3' endif " Build encodings. let &fileencodings = 'ucs-bom' if &encoding !=# 'utf-8' let &fileencodings .= ',' . 'ucs-2le' let &fileencodings .= ',' . 'ucs-2' endif let &fileencodings .= ',' . s:enc_jis let &fileencodings .= ',' . 'utf-8' if &encoding ==# 'utf-8' let &fileencodings .= ',' . s:enc_euc let &fileencodings .= ',' . 'cp932' elseif &encoding =~# '^euc-\%(jp\|jisx0213\)$' let &encoding = s:enc_euc let &fileencodings .= ',' . 'cp932' let &fileencodings .= ',' . &encoding else " cp932 let &fileencodings .= ',' . s:enc_euc let &fileencodings .= ',' . &encoding endif let &fileencodings .= ',' . 'cp20932' unlet s:enc_euc unlet s:enc_jis let did_encoding_settings = 1 endif " 2.2. END}}} if has('kaoriya') set fileencodings=guess endif " When do not include Japanese, use encoding for fileencoding. function! g:ReCheck_FENC() "{{{ let is_multi_byte = search("[^\x01-\x7e]", 'n', 100, 100) if &fileencoding =~# 'iso-2022-jp' && !is_multi_byte let &fileencoding = &encoding endif endfunction"}}} Autocmd BufReadPost * call g:ReCheck_FENC() " Default fileformat. set fileformat=unix " Automatic recognition of a new line cord. set fileformats=unix,dos,mac set ambiwidth=double " Command group opening with a specific character code again."{{{ " In particular effective when I am garbled in a terminal. " Open in UTF-8 again. command! -bang -bar -complete=file -nargs=? Utf8 \ edit ++enc=utf-8 " Open in iso-2022-jp again. command! -bang -bar -complete=file -nargs=? Iso2022jp \ edit ++enc=iso-2022-jp " Open in Shift_JIS again. command! -bang -bar -complete=file -nargs=? Cp932 \ edit ++enc=cp932 " Open in EUC-jp again. command! -bang -bar -complete=file -nargs=? Euc \ edit ++enc=euc-jp " Open in UTF-16 again. command! -bang -bar -complete=file -nargs=? Utf16 \ edit ++enc=ucs-2le " Open in UTF-16BE again. command! -bang -bar -complete=file -nargs=? Utf16be \ edit ++enc=ucs-2 " Aliases. command! -bang -bar -complete=file -nargs=? Jis Iso2022jp command! -bang -bar -complete=file -nargs=? Sjis Cp932 command! -bang -bar -complete=file -nargs=? Unicode Utf16 " }}} " Tried to make a file note version."{{{ " Don't save it because dangerous. command! WUtf8 setlocal fenc=utf-8 command! WIso2022jp setlocal fenc=iso-2022-jp command! WCp932 setlocal fenc=cp932 command! WEuc setlocal fenc=euc-jp command! WUtf16 setlocal fenc=ucs-2le command! WUtf16be setlocal fenc=ucs-2 " Aliases. command! WJis WIso2022jp command! WSjis WCp932 command! WUnicode WUtf16 " }}} " Appoint a line feed."{{{ command! -bang -complete=file -nargs=? WUnix \ write ++fileformat=unix | edit command! -bang -complete=file -nargs=? WDos \ write ++fileformat=dos | edit command! -bang -complete=file -nargs=? WMac \ write ++fileformat=mac | edit " }}} if has('multi_byte_ime') set iminsert=0 imsearch=0 endif