On 23/04/09 15:24, David Fishburn wrote:
>
> On Thu, Apr 23, 2009 at 4:41 AM, Dennis Benzinger
> <[email protected]> wrote:
> ...
>> What does :set enc? return? If enc is not set to a Unicode encoding I
>> think Vim won't be able to represent every Unicode character in memory.
>> Therefore you'll get a conversion error when Vim tries to convert your
>> file from UTF-16LE to its internal encoding.
>
> When I modified some of my Vim settings following this guide:
> http://vim.wikia.com/wiki/Working_with_Unicode
>
> Before opening the file, everything worked.
> So now I will go back and make 1 change at a time and see if I can
> still open the file.
>
>
> The Vim tip is good, but it doesn't really spell things out for this
> type of person:
> 1. Works in latin1 (English) all day
> 2. Only occassionally opens up a unicode file
>
> I am worried that adding this to my vimrc:
>
> if has("multi_byte")
> if&termencoding == ""
> let&termencoding =&encoding
> endif
> set encoding=utf-8
> setglobal fileencoding=utf-8 bomb
> set fileencodings=ucs-bom,utf-8,latin1
> endif
>
> Will affect all the new files I create and end up turning them into
> unicode files rather than my regular latin1 files.
>
> The only changes I want to make is to allow me to open unicode files
> if the file is already in unicode and leave everything else as I have
> it today (with default values on an English XP machine).
>
> Thanks for the response.
> Dave
Sorry for the late response, I've been having trouble keeping up with
incoming email recently.
To open new files in Latin1 by default, replace utf-8 by latin1 in the
"setglobal fileencoding" line. ('bomb' can remain set if you want to
have a BOM on newly created Unicode files, which I recommend; it has no
effect on non-Unicode files.)
Note also that 7-bit ASCII data is represented identically in all three
of US-ASCII, Latin1 and UTF-8, so as long as a Latin1 file of yours
contains no character above 0x7F it doesn't matter if Vim sees the file
as UTF-8. If, however, you create the file in 7-bit ASCII, save it, and
later want to edit it and add "top-half" Latin1 characters to it, you'll
have to make sure that Vim saves it in Latin1, e.g. by using ":setlocal
fenc=latin1" before saving the file; or you can create it with top-half
characters from the start (for instance by underlining the main title
with "divide-by" characters), and Vim will save that newly-created file
in Latin1.
If you want to exceptionally create one file in UTF-8 when
'fileencoding' (singular) is set globally to Latin1, just use the ++enc
modifier when creating the file, e.g.
:e ++enc=utf-8 newfile.txt
or
:new ++enc=utf-8 newfile.txt
Similarly for any other encoding other than your default, e.g. utf-16le
for "Windows-style Unicode" files.
With this small change to the above snippet, you should be able to
create new files in Latin1 by default, open existing files in the
correct encoding (without the need to specify it) if they either have a
BOM or are in UTF-8 or Latin1, and open any file whose encoding you know
by specifying the ++enc=<encoding> modifier (as shown above) before the
filename to the command that opens the file.
Tip: with the following custom 'statusline', the status line of every
Vim window will display (on the right side) the 'fileencoding' and
'bomb' status of the buffer currently being edited in that window. It's
three lines, the middle one is quite long:
if has("statusline")
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc\ ==\
\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}][U+%04B]\ %-12.(%l,%c%V%)\ %P
endif
Best regards,
Tony.
--
It's not that I'm afraid to die. I just don't want to be there when it
happens.
-- Woody Allen
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---