{"id":3242,"date":"2012-07-20T14:40:11","date_gmt":"2012-07-20T06:40:11","guid":{"rendered":"http:\/\/jpuyy.com\/?p=3242"},"modified":"2020-10-09T19:21:09","modified_gmt":"2020-10-09T11:21:09","slug":"vim-set-encoding","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=3242","title":{"rendered":"vim\u67e5\u770b\u548c\u66f4\u6539\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f"},"content":{"rendered":"<h2>\u5728Vim\u4e2d\u67e5\u770b\u6587\u4ef6\u7f16\u7801<\/h2>\n<pre>:set fileencoding<\/pre>\n<p>\u5373\u53ef\u663e\u793a\u6587\u4ef6\u7f16\u7801\u683c\u5f0f\u3002<br \/>\n\u5982\u679c\u4f60\u53ea\u662f\u60f3\u67e5\u770b\u5176\u5b83\u7f16\u7801\u683c\u5f0f\u7684\u6587\u4ef6\u6216\u8005\u60f3\u89e3\u51b3 \u7528Vim\u67e5\u770b\u6587\u4ef6\u4e71\u7801\u7684\u95ee\u9898\uff0c\u90a3\u4e48\u5728<br \/>\n~\/.vimrc \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>set encoding=utf-8 fileencodings=utf-8<\/pre>\n<p>\u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u8ba9vim\u81ea\u52a8\u8bc6\u522b\u6587\u4ef6\u7f16\u7801\uff08\u53ef\u4ee5\u81ea\u52a8\u8bc6\u522bUTF-8\u6216 \u8005GBK\u7f16\u7801\u7684\u6587\u4ef6\uff09\uff0c\u5176\u5b9e\u5c31\u662f\u4f9d\u7167fileencodings\u63d0\u4f9b\u7684\u7f16\u7801\u5217\u8868\u5c1d\u8bd5\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\u5408\u9002 \u7684\u7f16\u7801\uff0c\u5c31\u7528latin-1(ASCII)\u7f16\u7801\u6253\u5f00\u3002<\/p>\n<h2>\u4ee5\u6307\u5b9a\u7684\u7f16\u7801\u6253\u5f00\u67d0\u6587\u4ef6<\/h2>\n<p>\u5982\u6253\u5f00windows\u4e2d\u4ee5ANSI\u4fdd\u5b58\u7684\u6587\u4ef6<\/p>\n<pre>vim file.txt -c \"e ++enc=GB18030\"<\/pre>\n<h2>\u6587\u4ef6\u7f16\u7801\u8f6c\u6362<\/h2>\n<p>\u5728Vim\u4e2d\u76f4\u63a5\u8fdb\u884c\u8f6c\u6362\u6587\u4ef6\u7f16\u7801,\u6bd4\u5982\u5c06\u4e00\u4e2a\u6587\u4ef6\u8f6c\u6362\u6210utf-8\u683c\u5f0f<\/p>\n<pre>:set fileencoding=utf-8<\/pre>\n<p>\u67e5\u770b\u6587\u4ef6\u683c\u5f0f<\/p>\n<pre>:set fileformat?<\/pre>\n<p>\u8bbe\u7f6e\u6587\u4ef6\u683c\u5f0f\u4e3a unix<\/p>\n<pre>:set fileformat=unix<\/pre>\n<p>\u8bbe\u7f6e Byte Order Mark (BOM)<\/p>\n<pre>\r\n:set bomb\r\n<\/pre>\n<p>\u53ea\u4fdd\u7559\u6587\u4ef6 file a.txt \u4e3a UTF-8 Unicode (with BOM) text, with CRLF line terminators<\/p>\n<pre>\r\n:e ++ff=dos\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Vim\u4e2d\u67e5\u770b\u6587\u4ef6\u7f16\u7801 :set fileencoding \u5373\u53ef\u663e\u793a\u6587\u4ef6\u7f16\u7801\u683c\u5f0f\u3002 \u5982\u679c\u4f60\u53ea\u662f\u60f3\u67e5\u770b\u5176\u5b83\u7f16\u7801\u683c\u5f0f\u7684\u6587\u4ef6\u6216\u8005\u60f3\u89e3\u51b3 \u7528Vim\u67e5\u770b\u6587\u4ef6\u4e71\u7801\u7684\u95ee\u9898\uff0c\u90a3\u4e48\u5728 ~\/.vimrc \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a set encoding=utf-8 fileencodings=utf-8 \u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u8ba9vim\u81ea\u52a8\u8bc6\u522b\u6587\u4ef6\u7f16\u7801\uff08\u53ef\u4ee5\u81ea\u52a8\u8bc6\u522bUTF-8\u6216 \u8005GBK\u7f16\u7801\u7684\u6587\u4ef6\uff09\uff0c\u5176\u5b9e\u5c31\u662f\u4f9d\u7167fileencodings\u63d0\u4f9b\u7684\u7f16\u7801\u5217\u8868\u5c1d\u8bd5\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\u5408\u9002 \u7684\u7f16\u7801\uff0c\u5c31\u7528latin-1(ASCII)\u7f16\u7801\u6253\u5f00\u3002 \u4ee5\u6307\u5b9a\u7684\u7f16\u7801\u6253\u5f00\u67d0\u6587\u4ef6 \u5982\u6253\u5f00windows\u4e2d\u4ee5ANSI\u4fdd\u5b58\u7684\u6587\u4ef6 vim file.txt -c &#8220;e ++enc=GB18030&#8221; \u6587\u4ef6\u7f16\u7801\u8f6c\u6362 \u5728Vim\u4e2d\u76f4\u63a5\u8fdb\u884c\u8f6c\u6362\u6587\u4ef6\u7f16\u7801,\u6bd4\u5982\u5c06\u4e00\u4e2a\u6587\u4ef6\u8f6c\u6362\u6210utf-8\u683c\u5f0f :set fileencoding=utf-8 \u67e5\u770b\u6587\u4ef6\u683c\u5f0f :set fileformat? \u8bbe\u7f6e\u6587\u4ef6\u683c\u5f0f\u4e3a unix :set fileformat=unix \u8bbe\u7f6e Byte Order Mark (BOM) :set bomb \u53ea\u4fdd\u7559\u6587\u4ef6 file a.txt \u4e3a UTF-8 Unicode (with BOM) text, with CRLF line terminators :e ++ff=dos<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94],"tags":[23],"class_list":["post-3242","post","type-post","status-publish","format-standard","hentry","category-vim","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3242"}],"version-history":[{"count":12,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3242\/revisions"}],"predecessor-version":[{"id":9124,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3242\/revisions\/9124"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}