Skip to content

Instantly share code, notes, and snippets.

@lotem
Last active April 21, 2026 10:52
Show Gist options
  • Select an option

  • Save lotem/5440677 to your computer and use it in GitHub Desktop.

Select an option

Save lotem/5440677 to your computer and use it in GitHub Desktop.
Rime 自定義短語文件樣例
# Rime table
# coding: utf-8
#@/db_name custom_phrase.txt
#@/db_type tabledb
#
# 用於【朙月拼音】系列輸入方案
# 【小狼毫】0.9.21 以上
#
# 請將該文件以UTF-8編碼保存爲
# Rime用戶文件夾/custom_phrase.txt
#
# 碼表各字段以製表符(Tab)分隔
# 順序爲:文字、編碼、權重(決定重碼的次序、可選)
#
# 雖然文本碼表編輯較爲方便,但不適合導入大量條目
#
# 出現在以下這行註釋之後的 # 不再識別爲註釋:
# no comment
中州韻輸入法引擎 rime 3
Rime Input Method Engine rime 2
https://rime.im/ rime 1
星際我爭霸 starcraft
tassadar@protoss.net email
@gatspy

gatspy commented Dec 16, 2025

Copy link
Copy Markdown

rime 自定义短语支持 换行吗?

@wallleap

Copy link
Copy Markdown

rime 自定义短语支持 换行吗?

同问,写的 \n 原样输出了

@wallleap

wallleap commented Apr 21, 2026 •

Copy link
Copy Markdown

参考 https://github.com/hchunhui/librime-lua/blob/master/sample/lua/single_char.lua,自己写了个 lua 脚本,支持替换 \\n 为 \n,目前只有这个需求,如果有其他的需要替换可以自己修改代码:

-- lua/new_line.lua
-- 在方案补丁中新增 'engine/filters/@before last': lua_filter@*new_line

local M = {}

function M.init(env)

end

function M.func(input)
  for cand in input:iter() do
    -- 处理换行符 如果只需要 custom_phrase 里面的转换,判断一下 cand.type 是否为 user_table 就可以了
    if (cand.text:match("\\n")) then
      local replaced_text = string.gsub(cand.text, "\\n", "\n")

      -- 生成新候选(关键!)候选文字不能直接修改,注释可以
      local new_cand = Candidate(
        cand.type,
        cand.start,
        cand._end,
        replaced_text, -- 你想要的文字
        cand.comment -- 你想要的注释
      )
      
      -- 保留原权重(不影响排序)
      new_cand.quality = cand.quality

      yield(new_cand)
    else
      yield(cand)
    end
  end
end

return M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment