1

我对 vim 相当陌生,并且开始使用编辑器作为 vim 的新 javascript 项目(目前也在学习)。

我发现有一些样式指南的预设,以及AirbnbGoogle和其他一些提供的 linting。我还发现我可以使用合成的 vim 插件,它可以帮助我在 vim 中启用 linting 和样式检查。

但我不知道如何在vim中链接这些东西?我需要创建哪些配置文件以及如何在 Syntastic vim 插件中启用这些功能?我还想在文件保存功能上启用 jscs 自动修复。

编辑:我也在使用 es6 的反应。

任何基本或细节方向,实现相同的教程链接都会有所帮助。

谢谢

4

1 回答 1

4

在您的主目录中创建(或编辑)名为 的文件.vimrc,您可以通过将此行添加到您的.vimrc

let g:syntastic_javascript_checkers = ['jscs']

至于在写入时自动修复代码,请参阅此问题的答案:如何将 jscs 自动修复功能集成到 vim 中?


建议/更新

JSCS 现在与 ESlint 合并,所以你最终应该切换 linter,你可以编辑你的行.vimrc以使用 'eslint' 代替;您可以使用文件或eslint 的配置文档.eslintrc中详述的其他几个选项来配置 eslint,以使其了解 es6/react 的东西,目前我设置可以在不同的情况下使用不同的 linter,如下所示:.vimrc

if has("autocmd")
    " use google/jshint for js "
    autocmd FileType javascript.js let g:syntastic_javascript_checkers = ['gjslint','jshint']
    " use eslint for jsx "
    autocmd FileType javascript.jsx let g:syntastic_javascript_checkers = ['eslint']
else
    " if an older version of vim without autocmd just use google/jshint "
    let g:syntastic_javascript_checkers = ['gjslint','jshint']
endif

我已经修改了该答案中的代码以使用 eslint

function! FixJS()
    "Save current cursor position"
    let l:winview = winsaveview()
    "run eslint fix on current buffer"
    ! eslint --fix %
    "Restore cursor position"
    call winrestview(l:winview)
endfunction
command! FixJS :call FixJS()

"Run the FixJS command just before the buffer is written for *.js files"
autocmd BufWritePre *.js FixJS

应该在写入时或使用命令时自动修复代码:FixJS

于 2016-06-03T15:11:06.067 回答