gvim編UTF-8的文件

Windows 的 gvim 要編 UTF-8 要做的設定..
設 .vimrc
不過我記得預設是 UTF-8 讀都沒有問題..
寫也可以.. 不過寫完後是存 Big5 的編碼..
設定檔如下
Win32-UTF8-vim


轉載自 Win32-UTF8-vim
" piaip's gvim settings for gvim/win32 with UTF8
" optimized for Traditional Chinese users
" last update: Mon Jun 7 17:59:54 CST 2004
let $LANG="zh_TW.UTF-8" " locales
set encoding=utf-8 " ability
set fileencoding=big5 " prefer
" charset detect list. ucs-bom must be earlier than ucs*.
set fileencodings=ascii,ucs-bom,utf-8,ucs-2,ucs-le,sjis,big5,latin1
" for console mode we use big5
if has("gui_running")
set termencoding=utf-8
else
set termencoding=big5
endif
" vim:ft=vim
==========================
根據 myhsu 的問題做的測試.
gvim 如果不設 set fileencoding=utf-8
預設就會存成 big5,
如果 設定 set fileencoding=utf-8
存檔就會存成 utf-8
如果檔案本身就是 utf-8.
在 gvim 編輯後.. 還是會存成 utf-8.. 不會存成 big5
(gvim 自動判斷)
==========================
UTF-8 Big5 皆可讀取的設定
"============utf8 ===============
" piaip's gvim settings for gvim/win32 with UTF8
" optimized for Traditional Chinese users
" last update: Mon Jun 7 17:59:54 CST 2004
"let $LANG="zh_TW.UTF-8" " locales
"set encoding=utf-8 " ability
"set fileencoding=big5 " prefer
" charset detect list. ucs-bom must be earlier than ucs*.
"set fileencodings=ascii,ucs-bom,utf-8,ucs-2,ucs-le,sjis,big5,latin1
" for console mode we use big5
" == 下面這三行是主要的
" 參考自 Unicode 的 Vim區
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
"set encoding=utf8
set tenc=utf8
" == encoding 不要設的話. menu bar 就不會變亂碼.
if has("gui_running")
set termencoding=utf-8
else
set termencoding=big5
endif
" vim:ft=vim
"============utf8 ===============
不過設完後記事本存的 UTF-8 檔還是會有亂碼.
因為記事本會自己在 UTF-8 檔前面加 BOM(就是些怪東西).
造成還是無法看.. 不過除了記事本外的都沒有問題就是了 🙂
===============================
目前 Windows 的 .vimrc 檔完整內容.
======
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
if &sh =~ '\ ' . arg3 . '"'
else
silent execute '!C:\Program" Files\Vim\vim63\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
endif
endfunction
"set fileencoding=taiwan
"set fileencoding=utf-8
"set guifontset=8x16,kc15f,-*-16-*-big5-0
set cindent
set smartindent
"set backup
"set backupdir=~/.bak
set backupdir=D:\bak
"set enc=taiwan
set hls
set nocompatible
set sw=3
set showmatch
set background=light
set nu
colorscheme desert
syntax on
set guifont=mingliu:h12
highlight Comment ctermfg=darkcyan
highlight Search term=reverse ctermbg=4 ctermfg=7
highlight Normal ctermbg=black ctermfg=white
" Necessary. This setting tells vim to load latex-suite
" when a tex file opened.
filetype plugin on
" Optional. This enables automatic indentation as you
" type.
filetype indent on
"============utf8 ===============
" piaip's gvim settings for gvim/win32 with UTF8
" optimized for Traditional Chinese users
" last update: Mon Jun 7 17:59:54 CST 2004
"let $LANG="zh_TW.UTF-8" " locales
"set encoding=utf-8 " ability
"set fileencoding=big5 " prefer
" charset detect list. ucs-bom must be earlier than ucs*.
"set fileencodings=ascii,ucs-bom,utf-8,ucs-2,ucs-le,sjis,big5,latin1
" for console mode we use big5
set fileencodings=utf-8,big5,euc-jp,gbk,euc-kr,utf-bom,iso8859-1
"set encoding=utf8
set tenc=utf8
if has("gui_running")
set termencoding=utf-8
else
set termencoding=big5
endif
" vim:ft=vim
"============utf8 ===============
======

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

在〈gvim編UTF-8的文件〉中有 1 則留言

myhsu 發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料