How can I change a file's encoding with vim?
来源:互联网 发布:北京网络公安报警电话 编辑:程序博客网 时间:2024/06/07 07:40
I'm used to using vim to modify a file's line endings:
$ file filefile: ASCII text, with CRLF line terminators$ vim file:set ff=mac:wq$ file filefile: ASCII text, with CR line terminators
Is it possible to use a similar process to change a file's unicode encoding? I'm trying the following, which doesn't work:
$ file file.xmlfile.xml: Unicode text, UTF-16, little-endian$ vim file:set encoding=utf-8:wq$ file file.xmlfile.xml: Unicode text, UTF-16, little-endian
I saw someone say that he could "set fileencoding=utf-8, then update and write the file, and it works," but I seem to be missing something, or else he was confused. I don't know what he meant by "then update."
---------------------
From the doc:
:write ++enc=utf-8 russian.txt
So you should be able to change the encoding as part of the write command.
While using vim to do it is perfectly possible, why don't you simply use iconv? I mean - loading text editor just to do encoding conversion seems like using too big hammer for too small nail.
Just:
iconv -f utf-16 -t utf-8 file.xml > file.utf8.xml
---------------------------------
Just like your steps, setting fileencoding should work. However, I'd like to add one "set bomb" to help editor consider the file as UTF8.
$ vim file:set bomb:set fileencoding=utf-8:wq
reference
http://stackoverflow.com/questions/778069/how-can-i-change-a-files-encoding-with-vim
- How can I change a file's encoding with vim?
- How can I get file extensions with JavaScript?
- How can i change the title?
- How do I set file.encoding for a junit test in ant?
- How do I set file.encoding for a junit test in ant?
- How do I set file.encoding for a junit test in ant?
- vim encoding change issue
- How to change a file's owner and group in Linux - 1.0(翻译)
- How can I change the TCP/IP tuning parameters?
- 变化太快,how can I do and change it?
- How can I play a wav-file from memory or BLOB-field?
- How can I find out which process and user is modifying a file?
- How do I install a file in my local repository along with a generic POM?
- How can I get a String from HID device in Python with evdev?
- How can I create a tray icon
- How can I create a tray icon
- How can I flip a UIImageView?
- How can I print a JavaScript object?
- 从宏观到细节
- 水樹 奈々 Blog 20140908 鶴姫の鎧に興奮っ!译文
- Linux系统分析工具之mpstat,iostat(二)
- PHP 图像处理
- Lua,Lua API,配置文件
- How can I change a file's encoding with vim?
- Asp.net Mvc使用PagedList分页
- C/C++中Static的作用详述
- Java NIO系列教程(八) SocketChannel
- Linux系统分析工具之vmstat,free,ping(三)
- ZOJ 3819 Average Score (2014牡丹江区域赛)
- C++判断字符串是否为数字
- OpenMP并行程序设计——Eclipse开发环境的搭建
- Linux系统分析工具之nicstat,dstat(四)