1 Star 0 Fork 0

chai2010/vimpinyin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PunctEngine.vim 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
" =============================================================================
"
" VimPinyin —— Vim 拼音输入法
"
" 作者: ChaiShushan<chaishushan@gmail.com>
" 版权: BSD
"
" =============================================================================
" UTF8无BOM编码
scriptencoding utf-8
" =============================================================================
"{{{
" 全角数字
let s:zhDigit = [
\'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
\]
" 全角字母
let s:zhAlphaLower = [
\'a', 'b', 'c', 'd', 'e', 'f', 'g',
\'h', 'i', 'j', 'k', 'l', 'm', 'n',
\'o', 'p', 'q', 'r', 's', 't',
\'u', 'v', 'w', 'x', 'y', 'z',
\]
let s:zhAlphaUpper = [
\'A', 'B', 'C', 'D', 'E', 'F', 'G',
\'H', 'I', 'J', 'K', 'L', 'M', 'N',
\'O', 'P', 'Q', 'R', 'S', 'T',
\'U', 'V', 'W', 'X', 'Y', 'Z',
\]
" 英文标点
let s:enPunctList = [
\'`', '~',
\'!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
\'-', '_', '=', '+',
\'[', '{', ']', '}', '\', '|',
\';', ':', "'", '"',
\',', '<', '.', '>', '/', '?',
\' ',
\]
" 中文标点(全角)
let s:zhPunctList = [
\'·', '~',
\'!', '@', '#', '¥', '%', '……', '&', '*', '(', ')',
\'-', '——', '=', '+',
\'【', '『', '】', '』', '、', '|',
\';', ':', '‘', '“',
\',', '《', '。', '》', '/', '?',
\' ',
\]
"}}}
" =============================================================================
"{{{
" 单双引号匹配
let s:cntSingleQuotation = 0
let s:cntDoubleQuotation = 0
" 处理可打印字符
" 字母/数字/标点/空格/tab
function! VimPinyin_PunctEngine_ProcessInput(keycode)
" 数字
if VimPinyin_Common_IsDigit(a:keycode)
if g:VimPinyin_modeFull
return s:zhDigit[a:keycode-char2nr('0')]
else
return nr2char(a:keycode)
end
endif
" 字母
if VimPinyin_Common_IsLower(a:keycode)
if g:VimPinyin_modeFull
return s:zhAlphaLower[a:keycode-char2nr('a')]
else
return nr2char(a:keycode)
end
endif
if VimPinyin_Common_IsUpper(a:keycode)
if g:VimPinyin_modeFull
return s:zhAlphaLower[a:keycode-char2nr('A')]
else
return nr2char(a:keycode)
end
endif
for i in range(len(s:enPunctList))
if a:keycode == char2nr(s:enPunctList[i])
if g:VimPinyin_modeFull || g:VimPinyin_modeFullPunct
if a:keycode == char2nr("'")
let cnt = s:cntSingleQuotation
let s:cntSingleQuotation = s:cntSingleQuotation+1
return (cnt%2 == 0)? '‘': '’'
elseif a:keycode == char2nr('"')
let cnt = s:cntDoubleQuotation
let s:cntDoubleQuotation = s:cntDoubleQuotation+1
return (cnt%2 == 0)? '“': '”'
else
return s:zhPunctList[i]
endif
else
return s:enPunctList[i]
endif
endif
endfor
return "punct: " . a:keycode
endfunction
" 重置状态
function! VimPinyin_PunctEngine_Reset()
let s:cntSingleQuotation = 0
let s:cntDoubleQuotation = 0
endfunction
"}}}
" =============================================================================
"{{{1 vim: foldmethod=marker:
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chai2010/vimpinyin.git
git@gitee.com:chai2010/vimpinyin.git
chai2010
vimpinyin
vimpinyin
master

搜索帮助