2011-03-31 2 views
1

Vim에서 cp1250 인코딩에 일부 중앙 유럽 문자가 있습니다. 으로 인코딩을 변경하면 인코딩 = utf-8으로 설정하면 <d0> 등과 같이 표시됩니다. 어떻게하면 그 문자를 전체 파일로 대체 할 수 있습니까? 예를 들어,?Vim에서 cp1250 특정 문자를 utf-8로 대체하는 방법

답변

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} 
+0

또는 iconv external 명령을 사용할 수 있습니다. – sehe

+0

@sehe : 아, 훨씬 좋습니다! 특히 전체 버퍼를 변환해야하는 경우. @ 루크, 확인, 당신은 약간의 빔 필터 ('!') 마술이 필요합니다. @sehe, 왜 우리가 투표를 할 수 있도록 대답으로 게시하지 않으시겠습니까? – sidyll

+0

솔직히 말해서 필터 프로그램을 호출하는 '단순함'이 마음에 들지만 내장 함수를 많이 사용하는 것에 대한 제안이 마음에 들었습니다! 나는 그것이 거기에 있었다는 것을 몰랐다. – sehe

3

sidyll 말했듯이, 당신 해야 정말 목적으로 사용의 iconv. Iconv는 물건을 알고있다. 그것은 털이 많은 인코딩, 온순한 코드 포인트, 카타카나, 표준화되지 않은, 정규형, 합성, 비 - 스페이스 문자 및 나머지를 모두 알고 있습니다.

:%!iconv -f cp1250 -t utf-8 

:%!iconv --from-code cp1250 --to-code utf-8 

이하 전체 버퍼를 필터링한다. 해야한다면

:he xxd 

원하는 경우 버퍼로드/저장시 자동으로 인코딩하는 방법에 대한 샘플을 얻을 수 있습니다.

iconv -l은 내 시스템에있는 많은 (약 1168 개) 인코딩을 허용하거나 알고 있습니다.

해피 해킹!

관련 문제