Vim Tips Wiki
(standard format)
(adjust Template:ScriptComments to remove id as no longer needed; minor tweaks)
 
Line 1: Line 1:
{{ScriptComments|3547|jianfan: transcoding simplified and traditional Chinese}}
+
{{ScriptComments|jianfan: transcoding simplified and traditional Chinese}}
   
 
==Work only with selected lines==
 
==Work only with selected lines==

Latest revision as of 07:59, 15 November 2011

Use this page to discuss script 3547 jianfan: transcoding simplified and traditional Chinese

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Work only with selected lines[]

I am trying to learn the Chinese writing system. I find it useful to be able to compare a line of text written with simplified characters with a line written with traditional characters. I do not understand Chinese, sorry.

The idea is to modify Peter Chan's jianfan script as follows:

"jianfan : convert only selected lines
com! -ra -nargs=? Tcn :call G2B(<args>)
com! -ra -nargs=? Scn :call B2G(<args>)

function! G2B(...)
  let jianti=""
  let fanti=""
  "fsl 是第一个选中的行
  let fsl = line("'<")
  "lsl 是最后选中的行
  let lsl = line("'>")
  if fsl > lsl
    let temp = fsl
    let fsl = lsl
    let lsl = temp
  end
  exe 'normal '.fsl.'gg'
  let i=fsl
  while i<=lsl
    let curLine=getline(".")
    let newCurLine=tr(curLine,jianti,fanti)
    let result=setline(".",newCurLine)
    normal j
    let i=i+1
  endwhile
  exe 'normal '.fsl.'gg'
endfunction

function! B2G(...)
  let jianti=""
  let fanti=""
  "fsl 是第一个选中的行
  let fsl = line("'<")
  "lsl 是最后选中的行
  let lsl = line("'>")
  if fsl > lsl
    let temp = fsl
    let fsl = lsl
    let lsl = temp
  end
  exe 'normal '.fsl.'gg'
  let i=fsl
  while i<=lsl
    let curLine=getline(".")
    let newCurLine=tr(curLine,fanti,jianti)
    let result=setline(".",newCurLine)
    normal j
    let i=i+1
  endwhile
  exe 'normal '.fsl.'gg'
endfunction
".vimrc 简化汉字和传统汉字转换
"vnoremap <c-t> :Tcn<CR>
"vnoremap <c-s> :Scn<CR>

Usage[]

  • In normal mode, select lines with V
  • Press Ctrl-s to convert the selected lines to simplified Chinese.
  • Press Ctrl-t to convert the selected lines to traditional Chinese.

MRS 11:32, July 10, 2011 (UTC)

Comments[]