我在Vim中使用了cp1250編碼中的中歐字符。當我用set encoding = utf-8更改編碼時,它們看起來像<d0>
等。在這種情況下,我怎樣才能在整個文件中替換這些字符,即它們應該是什麼?如何在Vim中將cp1250特定字符替換爲utf-8
1
A
回答
1
您可以將encoding
設置爲文件編碼的值,termencoding
設置爲UTF-8的值。見The vim mbyte documentation。
2
的iconv()
功能可能是有用的:
iconv({expr}, {from}, {to}) *iconv()*
The result is a String, which is the text {expr} converted
from encoding {from} to encoding {to}.
When the conversion fails an empty string is returned.
The encoding names are whatever the iconv() library function
can accept, see ":!man 3 iconv".
Most conversions require Vim to be compiled with the |+iconv|
feature. Otherwise only UTF-8 to latin1 conversion and back
can be done.
This can be used to display messages with special characters,
no matter what 'encoding' is set to. Write the message in
UTF-8 and use:
echo iconv(utf8_str, "utf-8", &enc)
Note that Vim uses UTF-8 for all Unicode encodings, conversion
from/to UCS-2 is automatically changed to use UTF-8. You
cannot use UCS-2 in a string anyway, because of the NUL bytes.
{only available when compiled with the +multi_byte feature}
3
正如sidyll說,你確實應該使用的iconv爲宗旨。 Iconv知道的東西。它知道所有的毛茸茸的編碼,固定的代碼點,片假名,非規範化,規範形式,組合,非間距字符和其他。
:%!iconv --from-code cp1250 --to-code utf-8
或更短
:%!iconv -f cp1250 -t utf-8
過濾整個緩衝區。如果你這樣做
:he xxd
你會得到一個如何自動編碼緩存加載/保存如果你想要的樣本。
iconv -l
將列出您接受/瞭解的所有(很多:1168在我的系統上)編碼。
快樂黑客!
相關問題
- 1. vim將字符替換爲\ n
- 2. 如何將字符串轉換爲UTF8?
- 3. Vim替換一行中的某個字中的特定字符
- 4. 如何在Aptana Studio 3中將字符集更改爲CP1250?
- 5. 替換非UTF8字符
- 6. PHP:將字符串從特定字符串替換爲特定字符串
- 7. 如何將在Windows-1250/Cp1250中編碼的字符串轉換爲utf-8?
- 8. Vim替換特定條件
- 9. vim:將所有字符替換爲給定的標記
- 10. 將字節[]轉換爲UTF8字符串
- 11. 如何替換VIM中的換行符
- 12. 如何將utf8字符串轉換爲ascii字符串?
- 13. 如何將字符串從cp1250轉換爲Borland C++ Builder中的utf-8 6
- 14. 替換特定的字符
- 15. 如何在特定字符之前替換字符?
- 16. 如何從c#中的字符串替換特定的字符?
- 17. 如何替換包含python中特定字符的字符串?
- 18. vim字符串替換
- 19. 將utf8代碼點字符串轉換爲utf8 <U+0161>轉換爲utf8
- 20. 如何替換使用PHP ereg_replace替換所有特定字符?
- 21. 如何將特定字符串轉換爲特定的int
- 22. 將latin1字符串轉換爲utf8?
- 23. 將unicode字符串轉換爲utf8
- 24. 將字符串轉換爲UTF8
- 25. 如何使用vim將文字「\ n」替換爲文字「\\ n」?
- 26. 爲什麼特殊字符「ù」在替換中被替換?
- 27. 如何將數字轉換爲UTF8字符?
- 28. 如何將UTF8字符轉換爲PHP中的數字字符實體
- 29. 如何在c#中的特定位置替換字符串?
- 30. 替換特定的字符在C++
或者你可以使用iconv外部命令 – sehe 2011-03-31 22:17:18
@sehe:啊,那好多了!特別是如果需要轉換整個緩衝區。 @Rook,檢查一下,你只需要一點Vim過濾器('!')魔法。 @sehe,爲什麼不把它作爲答案發布,以便我們能夠投票? – sidyll 2011-04-01 01:57:02
說實話,我喜歡調用過濾器程序的'簡單',但我喜歡使用內建函數的建議!我不知道它在那裏:) – sehe 2011-04-01 06:30:15