About: Detect encoding from the charset specified in HTML files   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

The following code can be put in vimrc to detect and use such an encoding specification: if has('autocmd') function! ConvertHtmlEncoding(encoding) if a:encoding ==? 'gb2312' return 'cp936' " GB2312 imprecisely means CP936 in HTML elseif a:encoding ==? 'iso-8859-1' return 'latin1' " The canonical encoding name in Vim elseif a:encoding ==? 'utf8' return 'utf-8' " Other encoding aliases should follow here else return a:encoding endif endfunction function! DetectHtmlEncoding() if &filetype != 'html' return endif normal m` normal gg if search('\c') != 0 let reg_bak=@" normal y$ let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+') let charset=ConvertHtmlEncoding(charset) normal `` let @"=reg_bak if &fileencodings == '' let auto_encodings=',' . &encoding . ',' else let auto_encodi

AttributesValues
rdfs:label
  • Detect encoding from the charset specified in HTML files
rdfs:comment
  • The following code can be put in vimrc to detect and use such an encoding specification: if has('autocmd') function! ConvertHtmlEncoding(encoding) if a:encoding ==? 'gb2312' return 'cp936' " GB2312 imprecisely means CP936 in HTML elseif a:encoding ==? 'iso-8859-1' return 'latin1' " The canonical encoding name in Vim elseif a:encoding ==? 'utf8' return 'utf-8' " Other encoding aliases should follow here else return a:encoding endif endfunction function! DetectHtmlEncoding() if &filetype != 'html' return endif normal m` normal gg if search('\c') != 0 let reg_bak=@" normal y$ let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+') let charset=ConvertHtmlEncoding(charset) normal `` let @"=reg_bak if &fileencodings == '' let auto_encodings=',' . &encoding . ',' else let auto_encodi
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1073(xsd:integer)
Category
  • HTML
  • File Handling
  • Encoding
Text
  • AutoFenc.vim
  • FencView.vim
  • charset.vim
Author
  • Wu Yongwei
Complexity
  • advanced
Created
  • 2005(xsd:integer)
ID
  • 199(xsd:integer)
  • 1074(xsd:integer)
  • 1708(xsd:integer)
  • 2721(xsd:integer)
NEXT
  • 1077(xsd:integer)
Rating
  • 3(xsd:integer)
abstract
  • The following code can be put in vimrc to detect and use such an encoding specification: if has('autocmd') function! ConvertHtmlEncoding(encoding) if a:encoding ==? 'gb2312' return 'cp936' " GB2312 imprecisely means CP936 in HTML elseif a:encoding ==? 'iso-8859-1' return 'latin1' " The canonical encoding name in Vim elseif a:encoding ==? 'utf8' return 'utf-8' " Other encoding aliases should follow here else return a:encoding endif endfunction function! DetectHtmlEncoding() if &filetype != 'html' return endif normal m` normal gg if search('\c') != 0 let reg_bak=@" normal y$ let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+') let charset=ConvertHtmlEncoding(charset) normal `` let @"=reg_bak if &fileencodings == '' let auto_encodings=',' . &encoding . ',' else let auto_encodings=',' . &fileencodings . ',' endif if charset !=? &fileencoding && \auto_encodings =~ ',' . &fileencoding . ',' silent! exec 'e ++enc=' . charset endif else normal `` endif endfunction " Detect charset encoding in an HTML file au BufReadPost *.htm* nested call DetectHtmlEncoding() endif Please notice that the nested autocommand is used to ensure the syntax highlighting is OK and the remembered cursor position is still kept. It is recommended to use set encoding=utf-8 in order to ensure successful encoding conversion.
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software