Script:3547
Talk0
1,599pages on
this wiki
this wiki
Revision as of 11:32, July 10, 2011 by JohnBeckett (Talk | contribs)
Use this page to discuss script 3547 3547
- 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)