Ⅰ. 插件描述
vim spell checker for code, understands CamelCase and snake_caseⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'shinglyu/vim-codespell'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'shinglyu/vim-codespell'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'shinglyu/vim-codespell'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/shinglyu/vim-codespell
Ⅳ. 文档说明
vim-codespell
A vim plugin for checking the spelling for source code. The main difference from the built-in spell checker is that it handles CamelCase, snake_case better, and you can add custom words to it.
Installation
- Enable vim python3 support
Install aspell
- Mac:
brew install aspell - Ubuntu:
sudo apt-get install aspell
- Mac:
Add it to vim with the vim plugin manager of your choice.
- Vundle: Add
Plugin 'shinglyu/vim-codespell'to your~/.vimrcand run:PluginInstall
- Vundle: Add
To use the custom dictionary, you need to build it.
- Go to the installed location of the plugin. (For Vundle on Mac it's
cd ~/.vim/bundle/vim-codespell) cd dict./build.sh
- Go to the installed location of the plugin. (For Vundle on Mac it's
Commands
:Codespell: Run the spell checker once- To run it everytime you save a
*.pyfile, add the following to your vimrc:
:autocmd BufWritePre *.py :CodespellTesting
sudo pip3 install pytest pytest-benchmark(Or usevirtualenv)py.test
Generating Dictionaries
You can add custom words to the dictionary.
- Create a text file in
dict/(e.g.dict/cs.list) of words, one word per line - Generate the dictionary
aspell --lang=en create master ./cs.dict < cs.listA dictionary file cs.dict will be generated in the current dir. The plugin will pick it up using the default filename.
- Test the dictionary locally:
cat file_to_be_checked.txt | aspell -l en -d cs.dict --dict-dir=./ --listThe --dict-dir must be specified otherwise aspell will check the default location.
Tips
- Check if
python3is supported in your vim build:vim --version, look for the string "+python3". - To load it temporarily for test,
cdtoplugin/, runvim -S codespell.vim. :match Error /\%2l\%>1c\%<4c./: highlight line 2 (\%2l) and column 2 (\%>1c) to column 3 (\%<4c), the.is required because the match is 0 width.
References
- Python's
viminterface doc - Learn vimscript the hard way