Vim关于Vue的生态链还是很少,不过凑活凑活还是能用的。

缩进

缩进采用的是两个空格,.vimrc配置:

au BufNewFile,BufRead *.html,*.js,*.vue set tabstop=2
au BufNewFile,BufRead *.html,*.js,*.vue set softtabstop=2
au BufNewFile,BufRead *.html,*.js,*.vue set shiftwidth=2
au BufNewFile,BufRead *.html,*.js,*.vue set expandtab
au BufNewFile,BufRead *.html,*.js,*.vue set autoindent
au BufNewFile,BufRead *.html,*.js,*.vue set fileformat=unix

语法高亮

重要的语法高亮,支持最好的应该是vim-vue

使用Vundle下载:

Plugin 'posva/vim-vue'
:PluginInstall

这样语法高亮基本上就实现了,不过会出现滑动过快高亮失效的情况,文档中给出的原因是vue包含html、css、js语句,vim-vue有时候会感到困惑,解决办法:

autocmd FileType vue syntax sync fromstart

如果想使用一些已经写好的html、css、js配置,可以添加:

autocmd BufRead,BufNewFile *.vue setlocal filetype=vue.html.javascript.css

语法检查

语法检查可以使用vim-syntastic/syntastic配合ESLint。

使用Vundle下载:

Plugin 'scrooloose/syntastic' 
:PluginInstall

配置eslint检查器:

let g:syntastic_javascript_checkers = ['eslint']

可以使用打开一个vue文件,输入命令:

:SyntasticInfo

可以看到:

Syntastic version: 3.8.0-101 (Vim 704, Linux, GUI)
Info for filetype: vue
Global mode: active
Filetype vue is active
The current file will be checked automatically
Available checker: eslint
Currently enabled checker: eslint

现在就差ESLint了。

ESLint

Vue的官方推荐ESLint插件是eslint-plugin-vue

下载:

npm install eslint eslint-plugin-vue

配置.eslintrc

{
"extends": ["plugin:vue/recommended"],
"plugins": [
"vue"
],
"parserOptions": {
"parser": "babel-eslint",
},
"rules": {
},
"settings": {
"html/html-extensions": [".html", ".vue"],
},
}

注意,配置中不要包含eslint-plugin-html插件,eslint-plugin-html会使eslint-plugin-vue失效,因为eslint-plugin-html会从<script>中提取内容,但eslint-plugin-vue是需要<script>和<template>标签的。

  "plugins": [
"vue",
- "html" //去除
]

这样,:w保存vue文件时就会有红块报错了:

在每行之前的 >> 表示该行中有语法错误,将光标移到该行,错误描述就会展示在 Vim 窗口的最底下。

输入:Errors命令也会打印出详细的报错信息。

缩进错误

配合eslint-plugin-standard使用的时候,如果<script>缩进如下:

<script>
let a = {
foo: 1,
bar: 2
}
</script>

会报缩进错误:

Expected indentation of 0 spaces but found 2. (indent)

官方给出了解决方法:vue/script-indent

{
"extends": ["plugin:vue/recommended", "standard"],
"plugins": [
"vue"
],
"parserOptions": {
"parser": "babel-eslint",
},
"rules": {
"vue/script-indent": ["error", 2, { "baseIndent": 1 }]
},
"settings": {
"html/html-extensions": [".html", ".vue"],
},
"overrides": [
{
"files": ["*.vue"],
"rules": {
"indent": "off"
}
}
]
}

一是添加rule:

"vue/script-indent": ["error", 2, { "baseIndent": 1 }]

数字2代表1次缩进2个空格,数字1代表缩进1次。

二是关闭默认indent:

  "overrides": [
{
"files": ["*.vue"],
"rules": {
"indent": "off"
}
}
]

over。可以愉悦得用Vim写Vue了。

最新文章

  1. Rafy 领域实体框架 - 公司内部培训视频
  2. 对于一个负数mod正数
  3. 【转】PHP实现连贯操作
  4. Mesos源码分析
  5. 《c程序设计语言》读书笔记--大写转小写
  6. 【转】eclipse怎么设置字体大小
  7. 给C++初学者的50个忠告(好文转载)
  8. JAVA程序猿面试题汇总
  9. ****K - Alien&#39;s Organ
  10. Sqlite常用sql语句
  11. ArcGIS 网络分析[8.5] 资料5 网络分析拓展模块及各种接口说明
  12. Java hashtable和hastmap的区别
  13. easyUI datagrid 多行多列数据渲染异常缓慢原因以及解决方法
  14. Thinkpad W520 + Ubuntu 12.04LTS, 13.10, 14.04LTS安装Nvidia显卡驱动设置
  15. Monkey测试简介
  16. git命令详解( 三 )
  17. Microsoft/Git-Credential-Manager-for-Mac-and-Linux
  18. js与jquery对象的互转
  19. leetcode134
  20. 记录:springmvc + mybatis + maven 搭建配置流程

热门文章

  1. [daily][netcat] 在UNIX socket上使用netcat
  2. Java基础语法入门01
  3. 如何彻底禁止win10易升更新(转)
  4. sublime There are no packages available for installation 问题的解决办法
  5. bootstrap引入
  6. ZooKeeper02
  7. Mybatis下的sql注入
  8. FG面经Prepare: BST to Double LinkedList
  9. 常见的四种文本自动分词详解及IK Analyze的代码实现
  10. html 类似雷达扫描效果 及 闪屏效果