Vim convert file encoding




















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. It could be useful to change the encoding just on the command line before the file is read:. See starting , --cmd. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. How can I change a file's encoding with vim? Ask Question. Asked 12 years, 9 months ago. Active 1 month ago. Viewed k times. Improve this question. Add a comment. Active Oldest Votes. Improve this answer. Johan 2, 1 1 gold badge 18 18 silver badges 15 15 bronze badges. Brian Agnew Brian Agnew k 36 36 gold badges silver badges bronze badges.

Notice that there is a difference between set encoding and set fileencoding In the first case, you'll change the output encoding that is shown in the terminal. Cristian Ciupitu And you have to type, for example:. However, is there are more general solution? I'm a bit bored of having to manually work out what the file encoding is and consulting the help every time I open an unusual file. Alternatively, there are plugins like AutoFenc and fencview.

Do you have a byte-order-mark? Vim should detect this and work appropriately. From the doc - section When you start editing that bit Unicode file, and it has a BOM, Vim will detect this and convert the file to utf-8 when reading it. The 'fileencoding' option without s at the end is set to the detected value. In this case it is "utfle". That means it's Unicode, bit and little-endian. This file format is common on MS-Windows e. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Is it possible to automatically set UTF16 file encoding when opening a file of that type? Ask Question. Asked 9 years, 2 months ago. But it only works if translations for the language are available. Suppose you are in Germany, with the language set to German, but prefer to use "File" instead of "Datei".

The 'langmenu' option must be set before the menus are loaded. Once the menus have been defined changing 'langmenu' has no direct effect. Therefore, put the command to set 'langmenu' in your vimrc file. You will need to redefine them as well. If you don't see the language you want to use, you can do your own translations. The simplest way to do this is by copying one of the existing language files, and change it. First find out the name of your language with the " :language " command. Use this name, but with all letters made lowercase.

Then copy the file to your own runtime directory, as found early in 'runtimepath'. For example, for Unix you would do : :! For many European languages this is "latin1". Then each byte is one character.

That means there are different characters possible. For Asian languages this is not sufficient. These mostly use a double-byte encoding, providing for over ten thousand possible characters. This still isn't enough when a text is to contain several different languages. This is where Unicode comes in. It was designed to include all characters used in commonly used languages. This is the "Super encoding that replaces all others". But it isn't used that much yet. Fortunately, Vim supports these three kinds of encodings.

And, with some restrictions, you can use them even when your environment uses another language than the text. Nevertheless, when you only edit files that are in the encoding of your language, the default should work fine and you don't need to do anything.

The following is only relevant when you want to edit different languages. When you make Vim use Unicode internally, you will be able to edit files in any encoding. Unfortunately, the number of systems supporting Unicode is still limited. Thus it's unlikely that your language uses it.

You need to tell Vim you want to use Unicode , and how to handle interfacing with the rest of the system. This applies to the text in buffers files you are editing , registers , Vim script files, etc. You can regard 'encoding' as the setting for the internals of Vim. This example assumes you have this font on your system. The name in the example is for the X Window System. This font is in a package that is used to enhance xterm with Unicode support.

Try using the "Courier New" font. Only fixed-width fonts can be used though. The standard xterm that comes with XFree86 is one of them. Let's use that as an example.

First of all, the xterm must have been compiled with Unicode support. Start the xterm with the "-u8" argument. You might also need so specify a font. Example: xterm -u8 -fn -misc-fixed-medium-r-normalciso Now you can run Vim inside this terminal. Set 'encoding' to " utf-8 " as before. That's all.



0コメント

  • 1000 / 1000