Fandom

Vim Tips Wiki

Script:3547

1,624pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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 linesEdit

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>

UsageEdit

  • 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)

CommentsEdit

Also on Fandom

Random Wiki