This is what I am using (need +python):
"   %xx -> 对应的字符(到消息)[[[2
function Lilydjwg_hexchar()
  let chars = Lilydjwg_get_pattern_at_cursor('\(%[[:xdigit:]]\{2}\)\
+')
  if chars == ''
    echohl WarningMsg
    echo '在光标处未发现%表示的十六进制字符串!' "echo that the form of string cannot be
found there.
    echohl None
    return
  endif
  let str = substitute(chars, '%', '\\x', 'g')
  exe 'py print ''' . str . ''''
endfunction
"  取得光标处的匹配[[[2
function Lilydjwg_get_pattern_at_cursor(pat) "This is a function I
borrowed from another plugin
  let col = col('.') - 1
  let line = getline('.')
  let ebeg = -1
  let cont = match(line, a:pat, 0)
  while (ebeg >= 0 || (0 <= cont) && (cont <= col))
    let contn = matchend(line, a:pat, cont)
    if (cont <= col) && (col < contn)
      let ebeg = match(line, a:pat, cont)
      let elen = contn - ebeg
      break
    else
      let cont = match(line, a:pat, contn)
    endif
  endwh
  if ebeg >= 0
    return strpart(line, ebeg, elen)
  else
    return ""
  endif
endfunction

nmap <silent> t% :call Lilydjwg_hexchar()<CR>

After writing this to .vimrc, when I move the cursor to where the %xx
string is and press t%, I can see the decoded string.
Or you can just use a program called ascii2uni, eg:

echo %E9%A6%AC | ascii2uni -q -a J

and the output is 馬. You can combine this with the filter (:h filter)
feature of Vim to get lines of characters converted directly from
within Vim.

On Nov 11, 2:44 am, Sean <[email protected]> wrote:
> Hi,
>
> My input is from HTTP, 3 hard-coded bytes of UTF-8 hex value.
> What I want is 2 bytes unicode.
>
> For example:
> let input = "%E9%A6%AC"
> let output = "99AC"
>
> Based on the output, I can then get the real CJK: 馬.
>
> Is it possible to do it from within Vim?
>
> Thanks
>
> Sean
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to