文章目录
ALE介绍
ale是一个异步的检测插件,项目的介绍如下:
ALE (Asynchronous Lint Engine) is a plugin providing linting (syntax checking and semantic errors) in NeoVim 0.2.0+ and Vim 8 while you edit your text files, and acts as a Vim Language Server Protocol client.
ALE makes use of NeoVim and Vim 8 job control functions and timers to run linters on the contents of text buffers and return errors as texts changed in Vim. This allows for displaying warnings and errors in files being edited in Vim before files have been saved back to a filesystem.
In other words, this plugin allows you to lint while you type.
ALE offers support for fixing code with command line tools in a non-blocking manner with the
:ALEFix
feature, supporting tools in many languages, likeprettier
,eslint
,autopep8
, and more.
Github地址:Check syntax in Vim asynchronously and fix files, with Language Server Protocol (LSP) support
ALE安装
ale支持多种安装方式,详情参考项目github地址,这里以Vundle方式安装:
- 安装好Vundle插件
- 在
.vimrc
文件的Vundle插件列表里添加如下:
Plugin 'dense-analysis/ale'
- 打开vim然后运行命令
:PluginInstall
或者:BundleInstall
等待完成即可。 - 相应语言的
linter
,可以查看github上的支持列表,装好相应的linter
,加入环境变量即可。
Note:
- 由于Vundle插件后台还是在调用git进行代码克隆,如果失败请设置代理或者手动克隆项目到Vundle安装文件夹下,默认为
~/.vim/bundle/
。 - linux下的家目录为
~
,windows下的家目录为%HOME_PATH%
,如果在windows下可以使用\\
(whindows风格,必须是双反斜杠,取消转义)或者/
(linux风格)作为目录分割符。
ALE配置
详情参考项目github地址,在Vim中输入命令:h ale
可以查看各种相关内容,大部分配置使用默认的就可以了,这里给出一些简单显示配置(以下所有设置都在.vimrc
文件中写入,新修改的设置默认需要重启Vim才生效)。
自定义侧边提示符号
原始的ale侧边提示是这样:
--
表示警告,>>
表示错误,这样不是那么醒目,可以进行自定义设置:
" 自定义error和warning图标
let g:ale_sign_error = '✗'
let g:ale_sign_warning = '⚡'
重启打开Vim之后显示效果就变成这样了:
Note: 可以选择任何你喜欢的符号,出现乱码请检查Vim相关的编码设置以及字体是否支持该种符号。
自定义底部提示消息
默认的底部栏只显示出错消息:
可以设置添加更多的消息:
" 显示Linter名称,出错或警告等相关信息
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str