【问题标题】:Is there a quick way to rebuild spell files from wordlists?有没有一种快速的方法可以从单词表中重建拼写文件?
【发布时间】:2022-05-15 23:03:40
【问题描述】:

有没有办法告诉 vim 更新 'spelllang' 中列出的所有语言的拼写文件,以便从 vim 外部获取单词列表更改?

我已经开始在 git 中检查一个单词表文件,因为我厌倦了在多台计算机上添加相同的单词。我不想将拼写文件添加到 git 存储库,因为每次合并都会很丑陋,但是每当我打开 vim 时,任何最近的更新都会被忽略,直到我从 vim 内部执行一些重建拼写文件的操作,例如 @987654322 @ 将单词添加到字典中。

【问题讨论】:

    标签: vim


    【解决方案1】:

    我通过将 *.spl 添加到 .gitignore 文件然后在 vimrc 中解决了这个问题(它也与 GIT 同步,添加:

    for d in glob('~/.vim/spell/*.add', 1, 1)
        if filereadable(d) && (!filereadable(d . '.spl') || getftime(d) > getftime(d . '.spl'))
            exec 'mkspell! ' . fnameescape(d)
        endif
    endfor
    

    来源:https://vi.stackexchange.com/questions/5050/how-to-share-vim-spellchecking-additions-between-multiple-machines

    这将导致 vim 在每次启动 vim 时更新 .add 文件时重建 .spl 文件。

    【讨论】:

      【解决方案2】:

      如果您只有一个拼写文件,只需将其放入您的.vimrc

      exec 'silent mkspell! ' . &spellfile . '.spl'
      

      【讨论】:

      • 我不得不写这个:exec 'silent mkspell! ' . &spellfile . '.spl ' . &spellfile 命令是mkspell {outname} {inname}。在我的系统上,它使用你的命令创建了一个名为 en.local.utf-8.add.spl.utf-8.spl 的拼写数据库,带有额外的扩展名 utf-8.spl 而不仅仅是 en.local.utf-8.add.spl
      【解决方案3】:

      我为此创建了一个Vim plugin。它会自动找到拼写文件夹的路径,然后在启动时找到的任何单词列表上调用mkspell 以重新生成拼写文件。它还在拼写目录中创建.gitignore.gitattributes 文件以排除二进制拼写文件并使用Gi​​t 的union merge driver 来避免在合并来自两台不同机器的拼写文件时发生冲突。感谢Sato Katsura 提供mkspell 示例。

      https://github.com/micarmst/vim-spellsync

      【讨论】:

        【解决方案4】:

        您可以创建 git smudge/clean 过滤器和结帐后挂钩以调用 :mkspell

        $ mkdir -p ~/.vim/spell
        $ cd ~/.vim/spell
        $ git init
        $ echo '*.spl' > .gitignore
        $ touch words.utf-8.add
        $ git add . && git commit -m 'init'
        $ echo '*.add filter=spellfile' > .git/info/attributes
        $ git config filter.spellfile.smudge cat
        $ git config filter.spellfile.clean 'sort -u'
        $ cd .git/hooks/
        $ vim mkspell
        
        #!/bin/sh
        SPELL_FILE="`git rev-parse --show-toplevel`/words.utf-8.add" \
            vim -i NONE -u NORC -U NONE -V1 -nNesc '
                execute ":mkspell! " . fnameescape($SPELL_FILE) | echo "" | qall!
                '
        
        $ chmod +x ./mkspell
        $ ln -s ./mkspell post-checkout
        

        然后将spellfile 设置添加到您的~/.vimrc

        set spellfile=~/.vim/spell/words.utf-8.add
        

        【讨论】:

          【解决方案5】:

          使用字典的 git repo 是有意义的。问题在于通知vim 您的字典。一个简单的解决方案是映射 vim 以使用正确的字典。例如,如果您的话在my-dictionary.txt 中,那么您可以从vim 运行:

          :mkspell ~/.vim/spell/en_my_dict /path/to/git/repo/my-dictionary.txt
          

          我可能会使用类似的东西:

          " Set up Dictionary for check
          " This is will add your dictionary to existing list.
          " To use only your dictionary use, setlocal &spelllang=en_my_dict
          nmap <leader>ss :setlocal &spelllang=join(add(split(&spelllang, ','), 'en_my_dict'), ',')
          
          " Spell Check (Redo to disable)
          nmap <silent> <leader>sc :set spell!<CR>
          

          【讨论】:

          • 我已经按照我想要的方式设置了拼写文件(它在我的 vimrc 中配置为使用与 ~/.vim/spell/ 中的单词列表相对应的拼写语言,符号链接到 git 中的文件工作目录)。问题在于,每当该文件从 vim 外部更改时,vim 就会继续使用陈旧的 .spl 文件而不是较新的词表。
          猜你喜欢
          • 2011-02-16
          • 2020-12-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-30
          • 2010-10-01
          • 1970-01-01
          • 2013-04-09
          相关资源
          最近更新 更多