Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 2.0: A new version.

  • Loading branch information...
commit f73bc75b28b89b9bdab895ba5ef695898f16fdfb 1 parent dbd0f3c
Cyrus Baow authored December 21, 2012 vim-scripts committed December 25, 2012
58  README
@@ -7,6 +7,11 @@ Chinese
7 7
 
8 8
 目标:成为高效快速的中文输入法,就并且保持简单易学易用。
9 9
 
  10
+更新说明
  11
+------------
  12
+
  13
+最新的2.0版本,更新了中文编码方案,并添加了更多的快捷键。输入中文时可以更加舒适快速流畅,重码少,词汇多,简单易学。
  14
+
10 15
 主要特性
11 16
 ------------
12 17
 
@@ -37,38 +42,43 @@ Chinese
37 42
 快捷键
38 43
 --------
39 44
 
40  
-<Ctrl-x> 输入法开关
41  
-
42  
-<Ctrl-d> 取消当前的中文候选
43  
-
44  
-<Ctrl-h> 和 <Backspace> 一样,用于删除前边输入的字母
45  
-
46  
-<Ctrl-^> 显示菜单,设置输入法:
47  
-
48  
-<Ctrl-s> 连续输入时,把前置词上屏
49  
-
50  
-<Ctrl-f> 设置搜索关键词,用第一个字符进行全屏定位
51  
-
52  
-   ,g  开始搜索词汇
53  
-   ,f   开始全屏定位
54  
-
55  
-; 分号切换到临时英文,可在文件cy.cy当中的 EnChar 当中设置
  45
+   <Ctrl-\> 输入法开关.
56 46
 
57  
-{ 大括号切换到临时拼音 ,在文件cy.cy当中的 PyChar 当中设置
  47
+   <Ctrl-d> 取消当前的中文候选
58 48
 
59  
-` 反单引号(键盘左上角),当由大写英文字母切换到英文模式时,用于返回到中文模式
  49
+   <Ctrl-h> 和 <Backspace> 一样,用于删除前边输入的字母,为了方便
  50
+   还可选用<Ctrl-Space>
60 51
 
61  
-- 向上翻页
  52
+   <Ctrl-^> 显示菜单,设置输入法:
  53
+    (m) 码表切换
  54
+    (.) 中英标点切换
  55
+    (p) 最大词长: 设为 1 为单字模试
  56
+    (g) gb2312开关: 滤掉 gb2312 范围内的汉字
  57
+    (c) 简繁转换开关
  58
+    (q) 退出
62 59
 
63  
-= 向下翻页
  60
+   <Ctrl-f> 设置搜索关键词,用第一个字符进行全屏定位
  61
+   ,g 开始搜索词汇
  62
+   ,f 开始全屏定位
64 63
 
65  
-空格或数字选字, 回车输英文
  64
+   <Ctrl-s> 输入前置字符
  65
+   <Alt-u> 删除刚才新输入的字词
  66
+   \ 中英文切换
  67
+   <Ctrl-e> 中英文标点切换
66 68
 
67  
-; 分号选择第二候选词
  69
+   ' 单引号切换到临时英文,可在文件cy.cy当中的 EnChar 当中设置
  70
+   { 大括号切换到临时拼音 ,在文件cy.cy当中的 PyChar 当中设置
  71
+   输入大写英文字母自动切换到英文模式
68 72
 
69  
-f 普通状态时,可进行中英文的全屏快速定位跳转
  73
+   - 向上翻页
  74
+   = 向下翻页
70 75
 
71  
-t 同 f,跳转后光标在字符的前边
  76
+   空格或数字选字, 回车输英文
  77
+   ' 单引号选择第二候选词
  78
+   " 双引号选择第三候选词
  79
+   \ 反斜线选择第四候选词
  80
+   | 竖线选择第五候选词
  81
+    
72 82
 
73 83
 中文搜索方法
74 84
 ------------------
234,188  plugin/cy.cy
144701 additions, 89487 deletions not shown
187  plugin/cy.vim
... ...
@@ -1,8 +1,8 @@
1 1
 " CY Input Method for Chinese
2 2
 " 穿越中文输入法 (Vim 版本)
3 3
 " Author: Cyrus Baow <cy2081@baow.com>
4  
-" Last Change:	2012 Oct 19
5  
-" Release Version: 1.2
  4
+" Last Change:	2012 Dec 22
  5
+" Release Version: 2.0
6 6
 " License: GPL
7 7
 "
8 8
 " 主页:http://www.baow.com/help/cyim/
@@ -12,7 +12,6 @@
12 12
 " 特别说明和致谢:
13 13
 "  - ywvim          http://www.vim.org/scripts/script.php?script_id=2662
14 14
 "  - PreciseJump    http://www.vim.org/scripts/script.php?script_id=3437
15  
-"  - 哲哲豆音形码   http://zzdzzd.ys168.com/
16 15
 " 向以上软件作者表示感谢。
17 16
 "
18 17
 "
@@ -28,9 +27,12 @@
28 27
 " 快捷键
29 28
 " ------
30 29
 "
31  
-"   <Ctrl-x> 输入法开关.
  30
+"   <Ctrl-\> 输入法开关.
32 31
 "   <Ctrl-d> 取消当前的中文候选
33  
-"   <Ctrl-h> 和 <Backspace> 一样,用于删除前边输入的字母
  32
+"
  33
+"   <Ctrl-h> 和 <Backspace> 一样,用于删除前边输入的字母,为了方便
  34
+"   还可选用<Ctrl-Space>
  35
+"
34 36
 "   <Ctrl-^> 显示菜单,设置输入法:
35 37
 "    (m) 码表切换
36 38
 "    (.) 中英标点切换
@@ -44,16 +46,22 @@
44 46
 "   ,f 开始全屏定位
45 47
 "
46 48
 "   <Ctrl-s> 输入前置字符
  49
+"   <Alt-u> 删除刚才新输入的字词
  50
+"   \ 中英文切换
  51
+"   <Ctrl-e> 中英文标点切换
47 52
 "
48  
-"   ; 分号切换到临时英文,可在文件cy.cy当中的 EnChar 当中设置
  53
+"   ' 单引号切换到临时英文,可在文件cy.cy当中的 EnChar 当中设置
49 54
 "   { 大括号切换到临时拼音 ,在文件cy.cy当中的 PyChar 当中设置
50  
-"   大写英文字母切换到英文模式, 键盘左上角的反单引号 ` 回到中文模式 
  55
+"   输入大写英文字母自动切换到英文模式
51 56
 
52 57
 "   - 向上翻页
53 58
 "   = 向下翻页
54 59
 
55 60
 "   空格或数字选字, 回车输英文
56  
-"   ; 分号选择第二候选词
  61
+"   ' 单引号选择第二候选词
  62
+"   " 双引号选择第三候选词
  63
+"   \ 反斜线选择第四候选词
  64
+"   | 竖线选择第五候选词
57 65
 "
58 66
 " 中文搜索方法
59 67
 " -------------
@@ -90,17 +98,22 @@ let g:cy_search_brave = 1 " 是否使用CY搜索方式,1 表示打开,0 表
90 98
 
91 99
 " --------------------------------------------------------------------
92 100
 " 快捷键和参数设置 {{{
93  
-let s:cy_switch_key = "\<C-x>"  "输入法开关
  101
+let s:cy_switch_key = "\<C-\>"  "输入法开关
94 102
 let s:cy_find_input_key = "\<C-f>"    "设置搜索词
95 103
 let s:cy_cancle_key = "\<C-d>"   "取消当前输入
96 104
 let s:cy_input_pre_key = "\<C-s>"   "连续输入时只输入前置字符
97 105
 let s:cy_delete_key = "\<C-h>"   "删除前边的字母
98  
-let s:cy_tocn_key = '`'  "由大写字母切换到英文后返回中文的键
  106
+let s:cy_delete_key2 = "\<C-Space>"   "删除前边的字母
  107
+let s:cy_puncp_key = "\<C-e>"   "中英文标点切换
  108
+let s:cy_tocn_key = '\'  "由大写字母切换到英文后返回中文的键
99 109
 let s:cy_jump_map_key = ',f'
100 110
 let s:cy_find_map_key = ',g'
101 111
 let s:cy_jump_key1 = 'f'
102 112
 let s:cy_jump_key2 = 'F'
103 113
 let s:cy_jump_key3 = 't'
  114
+let s:cy_third_cn = '"'
  115
+let s:cy_four_cn = '\'
  116
+let s:cy_five_cn = '|'
104 117
 
105 118
 " 默认参数
106 119
 let s:varlst = [
@@ -119,7 +132,7 @@ let s:varlst = [
119 132
             \['cy_pageupkeys', "-"],
120 133
             \['cy_pagednkeys', "="],
121 134
             \['cy_inputzh_keys', " 	"],
122  
-            \['cy_inputzh_secondkeys', ";"],
  135
+            \['cy_inputzh_secondkeys', "'"],
123 136
             \['cy_inputen_keys', "
"],
124 137
             \]
125 138
 " 设置结束 }}}
@@ -434,10 +447,36 @@ function s:Cy_keymap() "{{{
434 447
         inoremap <buffer> <esc> <C-R>=Cy_toggle()<CR><C-R>=Cy_toggle()<CR><ESC>
435 448
     endif
436 449
     execute 'inoremap <buffer> '.s:cy_cancle_key.' <ESC>a'
  450
+    execute 'inoremap <buffer> '.s:cy_puncp_key.' <C-R>=<SID>Cy_puncp_en()<CR>'
437 451
     execute 'lnoremap <buffer> '.s:cy_find_input_key.' <C-R>=<SID>Cy_find_mode()<CR>'
438 452
     return ''
439 453
 endfunction "}}}
440 454
 
  455
+function s:Cy_puncp_en()
  456
+    if s:cy_{b:cy_parameters["active_mb"]}_zhpunc == 0
  457
+        call <SID>Cy_keymap_punc()
  458
+    else
  459
+        for p in keys(s:cy_{b:cy_parameters["active_mb"]}_puncdic)
  460
+            if p == '\'
  461
+                execute 'lunmap <buffer> ' . p
  462
+            else
  463
+                execute 'lunmap <buffer> ' . escape(p, '\|')
  464
+            endif
  465
+
  466
+        endfor
  467
+    endif
  468
+    if s:cy_{b:cy_parameters["active_mb"]}_enchar != ''
  469
+        execute 'lnoremap <buffer> <expr> ' . s:cy_{b:cy_parameters["active_mb"]}_enchar . ' <SID>Cy_enmode()'
  470
+    endif
  471
+    let s:cy_{b:cy_parameters["active_mb"]}_zhpunc = 1 - s:cy_{b:cy_parameters["active_mb"]}_zhpunc
  472
+    if s:cy_{b:cy_parameters["active_mb"]}_zhpunc == 1
  473
+        echo '中文标点'
  474
+    else
  475
+        echo '英文标点'
  476
+    endif
  477
+    return ''
  478
+endfunction
  479
+
441 480
 function s:Cy_UIsetting(m) "{{{
442 481
     let punc='。'
443 482
     if s:cy_{b:cy_parameters["active_mb"]}_zhpunc == 0
@@ -484,22 +523,7 @@ function s:Cy_UIsetting(m) "{{{
484 523
         call <SID>Cy_loadmb()
485 524
         call <SID>Cy_keymap()
486 525
     elseif par == '.'
487  
-        if s:cy_{b:cy_parameters["active_mb"]}_zhpunc == 0
488  
-            call <SID>Cy_keymap_punc()
489  
-        else
490  
-            for p in keys(s:cy_{b:cy_parameters["active_mb"]}_puncdic)
491  
-                if p == '\'
492  
-                    execute 'lunmap <buffer> ' . p
493  
-                else
494  
-                    execute 'lunmap <buffer> ' . escape(p, '\|')
495  
-                endif
496  
-
497  
-            endfor
498  
-        endif
499  
-        if s:cy_{b:cy_parameters["active_mb"]}_enchar != ''
500  
-            execute 'lnoremap <buffer> <expr> ' . s:cy_{b:cy_parameters["active_mb"]}_enchar . ' <SID>Cy_enmode()'
501  
-        endif
502  
-        let s:cy_{b:cy_parameters["active_mb"]}_zhpunc = 1 - s:cy_{b:cy_parameters["active_mb"]}_zhpunc
  526
+        call <SID>Cy_puncp_en()
503 527
     elseif par == 'p'
504 528
         let s:cy_{b:cy_parameters["active_mb"]}_maxphraselength = input('最大词长: ', s:cy_{b:cy_parameters["active_mb"]}_maxphraselength)
505 529
     elseif par == 'g'
@@ -679,6 +703,10 @@ function s:Cy_find_tip() "{{{
679 703
     echohl Keyword | echon g:cy_find_str_first | echohl None
680 704
     sleep 2
681 705
 endfunction "}}}
  706
+function s:Cy_undomap(char) "{{{
  707
+    let move_left = strchars(a:char) - 1
  708
+    execute 'imap <A-u>  <ESC>'.move_left.'dhxa'
  709
+endfunction "}}}
682 710
 
683 711
 function s:Cy_char(key) "{{{
684 712
     let char = ''
@@ -694,7 +722,7 @@ function s:Cy_char(key) "{{{
694 722
         let to_char = ''
695 723
         let key = nr2char(keycode)
696 724
         let keypat = '\V'.escape(key, '\')
697  
-        if (keycode == "\<BS>") || (keycode == char2nr(s:cy_delete_key)) "backspace
  725
+        if (keycode == "\<BS>") || (keycode == char2nr(s:cy_delete_key)) || (keycode == s:cy_delete_key2) "backspace
698 726
             if g:cy_to_english == 1
699 727
                 return key
700 728
             endif
@@ -780,6 +808,7 @@ function s:Cy_char(key) "{{{
780 808
                     return "\<Esc>"
781 809
                 endif
782 810
                 call setreg(g:cy_reg_name, word )
  811
+                call <SID>Cy_undomap(swap_char . word)
783 812
                 return swap_char . word
784 813
             endif
785 814
             let old_char = char
@@ -803,7 +832,16 @@ function s:Cy_char(key) "{{{
803 832
             if len(s:cy_pgbuf[s:cy_pagenr]) ==0
804 833
                 let showchar = ''
805 834
                 let char = ''
  835
+                if s:cy_{b:cy_parameters["active_mb"]}_zhpunc && has_key(s:cy_{b:cy_parameters["active_mb"]}_puncdic, key)
  836
+                    let key = <SID>Cy_puncp(key)
  837
+                    call <SID>Cy_undomap(buffer_char. key)
  838
+                    return buffer_char. key .<SID>Cy_ReturnChar()
  839
+                elseif s:cy_{b:cy_parameters["active_mb"]}_zhpunc == 0
  840
+                    call <SID>Cy_undomap(buffer_char. key)
  841
+                    return buffer_char. key .<SID>Cy_ReturnChar()
  842
+                endif
806 843
                 if len(g:cy_buffer)>0
  844
+                    call <SID>Cy_undomap(g:cy_buffer)
807 845
                     return g:cy_buffer.<SID>Cy_ReturnChar()
808 846
                 else
809 847
                     return "".<SID>Cy_ReturnChar()
@@ -869,8 +907,10 @@ function s:Cy_char(key) "{{{
869 907
                         return "\<Esc>"
870 908
                     endif
871 909
                     call setreg(g:cy_reg_name, word)
  910
+                    call <SID>Cy_undomap(buffer_char.word)
872 911
                     return buffer_char.word
873 912
                 endif
  913
+                call <SID>Cy_undomap(buffer_char)
874 914
                 return buffer_char.<SID>Cy_ReturnChar()
875 915
             "else
876 916
                 "return buffer_char
@@ -879,6 +919,7 @@ function s:Cy_char(key) "{{{
879 919
                 "return buffer_char.<SID>Cy_ReturnChar(showchar)."\<C-^>"
880 920
                 "return <SID>Cy_ReturnChar(showchar)
881 921
             endif
  922
+
882 923
         elseif '['.s:cy_{b:cy_parameters["active_mb"]}_inputzh_secondkeys.']' =~ keypat " input Second Chinese
883 924
             if len(old_char) == maxcodes
884 925
                 let buffer_char = temp_char
@@ -898,8 +939,82 @@ function s:Cy_char(key) "{{{
898 939
                     call s:Cy_find_tip()
899 940
                     return "\<Esc>"
900 941
                 endif
  942
+                call <SID>Cy_undomap(buffer_char.<SID>Cy_ReturnChar(secondcharidx))
901 943
                 return buffer_char.<SID>Cy_ReturnChar(secondcharidx)
902 944
             endif
  945
+            call <SID>Cy_undomap(buffer_char)
  946
+            return buffer_char.<SID>Cy_ReturnChar()
  947
+        elseif '['.s:cy_third_cn.']' =~ keypat " input third Chinese
  948
+            if len(old_char) == maxcodes
  949
+                let buffer_char = temp_char
  950
+            else
  951
+                let buffer_char = temp_char2
  952
+            endif
  953
+            let temp_char = ''
  954
+            let temp_char2 = ''
  955
+            if s:cy_pgbuf[s:cy_pagenr] != []
  956
+                let thirdcharidx = 1
  957
+                if len(s:cy_pgbuf[s:cy_pagenr][0]) >= 3
  958
+                    let thirdcharidx = 2
  959
+                endif
  960
+                if g:cy_find_mode == 1
  961
+                    let g:cy_find_str = <SID>Cy_ReturnChar(thirdcharidx)
  962
+                    let g:cy_find_mode = 0
  963
+                    call s:Cy_find_tip()
  964
+                    return "\<Esc>"
  965
+                endif
  966
+                call <SID>Cy_undomap(buffer_char.<SID>Cy_ReturnChar(thirdcharidx))
  967
+                return buffer_char.<SID>Cy_ReturnChar(thirdcharidx)
  968
+            endif
  969
+            call <SID>Cy_undomap(buffer_char)
  970
+            return buffer_char.<SID>Cy_ReturnChar()
  971
+        elseif '['.s:cy_four_cn.']' =~ keypat " input four Chinese
  972
+            if len(old_char) == maxcodes
  973
+                let buffer_char = temp_char
  974
+            else
  975
+                let buffer_char = temp_char2
  976
+            endif
  977
+            let temp_char = ''
  978
+            let temp_char2 = ''
  979
+            if s:cy_pgbuf[s:cy_pagenr] != []
  980
+                let fourcharidx = 1
  981
+                if len(s:cy_pgbuf[s:cy_pagenr][0]) >= 4
  982
+                    let fourcharidx = 3
  983
+                endif
  984
+                if g:cy_find_mode == 1
  985
+                    let g:cy_find_str = <SID>Cy_ReturnChar(fourcharidx)
  986
+                    let g:cy_find_mode = 0
  987
+                    call s:Cy_find_tip()
  988
+                    return "\<Esc>"
  989
+                endif
  990
+                call <SID>Cy_undomap(buffer_char.<SID>Cy_ReturnChar(fourcharidx))
  991
+                return buffer_char.<SID>Cy_ReturnChar(fourcharidx)
  992
+            endif
  993
+            call <SID>Cy_undomap(buffer_char)
  994
+            return buffer_char.<SID>Cy_ReturnChar()
  995
+        elseif '['.s:cy_five_cn.']' =~ keypat " input five Chinese
  996
+            if len(old_char) == maxcodes
  997
+                let buffer_char = temp_char
  998
+            else
  999
+                let buffer_char = temp_char2
  1000
+            endif
  1001
+            let temp_char = ''
  1002
+            let temp_char2 = ''
  1003
+            if s:cy_pgbuf[s:cy_pagenr] != []
  1004
+                let fivecharidx = 4
  1005
+                "if len(s:cy_pgbuf[s:cy_pagenr][0]) > 4
  1006
+                    "let fivecharidx = 4
  1007
+                "endif
  1008
+                if g:cy_find_mode == 1
  1009
+                    let g:cy_find_str = <SID>Cy_ReturnChar(fivecharidx)
  1010
+                    let g:cy_find_mode = 0
  1011
+                    call s:Cy_find_tip()
  1012
+                    return "\<Esc>"
  1013
+                endif
  1014
+                call <SID>Cy_undomap(buffer_char.<SID>Cy_ReturnChar(fivecharidx))
  1015
+                return buffer_char.<SID>Cy_ReturnChar(fivecharidx)
  1016
+            endif
  1017
+            call <SID>Cy_undomap(buffer_char)
903 1018
             return buffer_char.<SID>Cy_ReturnChar()
904 1019
         "elseif key =~ '[0-' . s:cy_{b:cy_parameters["active_mb"]}_listmax . ']' " number selection
905 1020
         elseif key =~ '[0-9]' " number selection
@@ -919,6 +1034,7 @@ function s:Cy_char(key) "{{{
919 1034
                     return "\<Esc>"
920 1035
                 endif
921 1036
                 call setreg(g:cy_reg_name, word)
  1037
+                call <SID>Cy_undomap(buffer_char.word)
922 1038
                 return buffer_char.word
923 1039
             else
924 1040
                 call <SID>Cy_echofinalresult([showchar, '[' . (s:cy_pagenr + 1) . ']', candidates, buffer_char])
@@ -931,6 +1047,7 @@ function s:Cy_char(key) "{{{
931 1047
             endif
932 1048
             let temp_char = ''
933 1049
             let temp_char2 = ''
  1050
+            call <SID>Cy_undomap(buffer_char)
934 1051
             return buffer_char.<SID>Cy_ReturnChar(showchar)
935 1052
         elseif keycode == char2nr("\<C-^>") "config tools
936 1053
             if len(old_char) == maxcodes
@@ -949,6 +1066,7 @@ function s:Cy_char(key) "{{{
949 1066
             endif
950 1067
             let temp_char = ''
951 1068
             let temp_char2 = ''
  1069
+            call <SID>Cy_undomap(buffer_char)
952 1070
             return buffer_char.<SID>Cy_ReturnChar()
953 1071
         elseif keycode == char2nr(s:cy_switch_key)  "switch status
954 1072
             if len(old_char) == maxcodes
@@ -963,10 +1081,12 @@ function s:Cy_char(key) "{{{
963 1081
         elseif keycode == char2nr(s:cy_find_input_key)  "find
964 1082
             let g:cy_find_mode = 1
965 1083
             return <SID>Cy_ReturnChar()
966  
-        elseif keycode == char2nr(s:cy_cancle_key)  "
967  
-            "return ""
  1084
+        elseif keycode == char2nr(s:cy_cancle_key)  " cancle input
968 1085
             return <SID>Cy_ReturnChar()
969 1086
         elseif s:cy_pgbuf[s:cy_pagenr] != [] "return first word and key
  1087
+            if key=="\<Esc>"
  1088
+                return key
  1089
+            endif
970 1090
             if s:cy_{b:cy_parameters["active_mb"]}_zhpunc && has_key(s:cy_{b:cy_parameters["active_mb"]}_puncdic, key)
971 1091
                 let key = <SID>Cy_puncp(key)
972 1092
             endif
@@ -977,6 +1097,7 @@ function s:Cy_char(key) "{{{
977 1097
             endif
978 1098
             let temp_char = ''
979 1099
             let temp_char2 = ''
  1100
+            call <SID>Cy_undomap(buffer_char.<SID>Cy_ReturnChar(0) . key)
980 1101
             return buffer_char.<SID>Cy_ReturnChar(0) . key 
981 1102
         endif
982 1103
         let keycode = getchar()
@@ -984,7 +1105,11 @@ function s:Cy_char(key) "{{{
984 1105
 endfunction "}}}
985 1106
 
986 1107
 function s:Cy_tocn() "{{{
987  
-    let g:cy_to_english = 0
  1108
+    if g:cy_to_english == 1
  1109
+        let g:cy_to_english = 0
  1110
+    else
  1111
+        let g:cy_to_english = 1
  1112
+    endif
988 1113
     return ""
989 1114
 endfunction "}}}
990 1115
 

0 notes on commit f73bc75

Please sign in to comment.
Something went wrong with that request. Please try again.