Skip to content

About

A neovim plugin to detect the encoding of a text file. neovim 中文输入改进计划

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Repository files navigation

tellenc.nvim

readthedocs pre-commit.ci status github/workflow

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors。 github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

luarocks

neovim 中文输入改进计划

我们的目标是:

  • 性能优先:
    • 用纯 lua 编写的 neovim 插件可能存在性能瓶颈。 不同于之前的 neovim 中文输入改进计划 。 我们鼓励利用各种现成的 C/C++/rust/go 等库实现 lua binding 来缓解性能问题。 代价是需要额外的编译。我们鼓励将插件构建打包为 rocks 格式。目前支持安装 rocks 安装包的 neovim 插件管理器有:
    • 减少开销。调用命令行接口会带来进程 fork 的开销。
      • 鼓励实现为 lua binding 。例如 librime/cppjieba 等库。
      • 通过通信协议与正在运行的程序通信。例如通过 dbus 协议和系统 输入法、 剪贴板、 通知 通信。 反面例子: tmux 的通信协议没有公开。必须通过命令行调用 tmux 。 替代品 zellij 则公开了 JSON-RPC 通信协议。 安装预编译好的 rocks 文件,节约构建时间。
  • 接近原生 vim 功能:尽可能接近原生 vim 体验。比如 vim 的 w/b/e/ge 不支持中文分词。 支持中文分词的 vim 插件也应该默认提供 w/b/e/ge 快捷键,而不是覆盖 W/B/E/gE 。 同时也要支持 vim 的 count 用法: 3w 。
  • 鼓励复用。
  • 清晰文档。
    • 在 Binding 中提供库的使用方法。
    • 在 Related Projects 中列出已有的解决方法以及其不足之处。如能给出性能的 test bench 会更好
    • 在 Similar Projects 中列出相似项目以供参考。

中文输入法

中文输入法的介绍。太长不看的总结如下:

  • 不建议使用单模式输入法。 相比多模式输入法, 单模式输入法的使用体验和系统输入法差异很大。如果坚持使用,建议使用 LSP 。因为 LSP 的跨编辑器性,可能会 得到更好的维护。
  • 对于系统输入法,注意到 GNU/Linux 下的 ibus/fcitx 等均支持 dbus 通信协议。使用 ime.nvim 性能更好。对于 macOS/Windows 输入法,目前没有通信协议或 lua binding 的支持。只能使用 命令行。
  • 对于 Vim 的嵌入式输入法, 推荐:

拼音模糊搜索

在 vim 中输入 /pinyin 搜索到 拼音 。 这里有一些 插件 。 替代方案是直接用中文输入法输入汉字选中后搜索。

中文分词跳转

参见 jieba.nvim 。

中文 linter/formatter

现在主流的 linter/formatter 都是基于 LSP 的实现。但基本都只支持英文。 这里有一些非 LSP 的中文 linter/formatter 。

中文字符编码识别

vi -u NONE test.txt
:set fileencoding=cp936
:put ='你好我是一个中国人'
:wq
vi -u NONE test.txt

Expected behaviour:

你好我是一个中国人

Actual behaviour:

ÄãºÃÎÒÊÇÒ»¸öÖйúÈË

在 vim 中 :edit ++filencoding=ENCODING test.txt 会用 ENCODING 编码打开 test.txt 。如果用户没有显式传入 ++filencoding ,则按照 :set fileencodings 的顺序查找。这可能会使用错误的编码导致乱码。注意到中文中有很多高频汉字,例如“的”、“是”, 所以可以通过查找高频汉字的编码来预测字符编码。 tellenc 使一个基于此原理来预测字符编码的 软件。 tellenc 不能保证预测一定正确,所以一旦预测失败,仍然需要通过 :edit ++filencoding=ENCODING test.txt 手动干预。

  • vim-fencview: 通过命令行调用 tellenc
  • 本项目。提供了:
    • 一个 tellenc 的 lua binding
    • neovim 插件

Install

rocks.nvim

Command style

:Rocks install tellenc.nvim

Declare style

~/.config/nvim/rocks.toml:

[plugins]
"tellenc.nvim" = "scm"

Then

:Rocks sync

or:

$ luarocks --lua-version 5.1 --local --tree ~/.local/share/nvim/rocks install tellenc.nvim
# ~/.local/share/nvim/rocks is the default rocks tree path
# you can change it according to your vim.g.rocks_nvim.rocks_path

lazy.nvim

require("lazy").setup {
  spec = {
    { "rimeinn/tellenc.nvim", lazy = false },
  },
}

Binding

local tellenc = require "tellenc".tellenc
print(tellenc "abc")
-- ascii
print(tellenc "你好")
-- utf-8

About

A neovim plugin to detect the encoding of a text file. neovim 中文输入改进计划

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages