一些关于Vim的JSHint / Syntastic问题

时间:2015-12-24 19:18:34

标签: vim vi jshint syntastic

我将Vim与Syntastic和JSHint结合使用,并且有一些我想修复的小故障行为。

  1. 每当我修改一行文字中的最后一个字符并保存(:w)时,我会立刻看到" ^ M"文字之前闪现(有时)消失。有时它会四处乱窜,我必须手动删除它。对此有什么处理以及如何防止它?
  2. 如果quickfix视图中有错误,如何在quickfix视图和Vim编辑器窗口之间切换焦点?
  3. Vim可能每分钟崩溃一次,我没有丝毫的线索,为什么,但它非常烦人。错误通常读取" Vim:捕获致命信号ABRT Vim:已完成。 [1] 6099 abort vi gulpfile.js"我该如何阻止这种情况?
  4. 这是我的.vimrc文件:

    set nocompatible              " be iMproved, required
    filetype off                  " required
    
    " set the runtime path to include Vundle and initialize
    set rtp+=~/.vim/bundle/Vundle.vim
    call vundle#begin()
    " alternatively, pass a path where Vundle should install plugins
    "call vundle#begin('~/some/path/here')
    
    " let Vundle manage Vundle, required
    Plugin 'VundleVim/Vundle.vim'
    
    " The following are examples of different formats supported.
    " Keep Plugin commands between vundle#begin/end.
    " plugin on GitHub repo
    Plugin 'tpope/vim-fugitive'
    " plugin from http://vim-scripts.org/vim/scripts.html
    "Plugin 'L9'
    " Git plugin not hosted on GitHub
    Plugin 'git://git.wincent.com/command-t.git'
    " git repos on your local machine (i.e. when working on your own plugin)
    "Plugin 'file:///home/gmarik/path/to/plugin'
    " The sparkup vim script is in a subdirectory of this repo called vim.
    " Pass the path to set the runtimepath properly.
    Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
    " Avoid a name conflict with L9
    "Plugin 'user/L9', {'name': 'newL9'}
    
    " All of your Plugins must be added before the following line
    call vundle#end()            " required
    filetype plugin indent on    " required
    " To ignore plugin indent changes, instead use:
    "filetype plugin on
    "
    " Brief help
    " :PluginList       - lists configured plugins
    " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
    " :PluginSearch foo - searches for foo; append `!` to refresh local cache
    " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
    "
    " see :h vundle for more details or wiki for FAQ
    " Put your non-Plugin stuff after this line
    
    " React.js/JSX syntax highlighting
    "Plugin 'mxw/vim-jsx'
    "
    "JSHint
    Plugin 'wookiehangover/jshint.vim'
    
    "Syntastic
    Plugin 'scrooloose/syntastic'
    
    "Syntastic configuration
    set statusline+=%#warningmsg#
    set statusline+=%{SyntasticStatuslineFlag()}
    set statusline+=%*
    
    let g:syntastic_always_populate_loc_list = 1
    let g:syntastic_auto_loc_list = 1
    let g:syntastic_check_on_open = 1
    let g:syntastic_check_on_wq = 0
    let g:syntastic_html_tidy_exec = 'tidy5'
    let g:syntastic_javascript_checkers = ['jshint']
    let g:JSHintHighlightErrorLine = 0
    
    
    
    
    
    syntax on
    set t_Co=256
    set ai
    set shiftwidth=4
    set tabstop=4
    set number
    "colorscheme monokai
    colorscheme skittles_berry
    

    感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

我不知道你的^M问题和崩溃问题来自哪里,但你不需要这么大的插件来完成这么简单的任务。

创建~/.vim/after/ftplugin/javascript.vim如果它不存在并粘贴以下行:

  • jshint的错误格式

    setlocal errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m,%-G%.%#
    
  • 告诉Vim使用jshint作为:make命令

    setlocal makeprg=jshint
    
  • 在写入时添加自动命令以在当前文件上运行:make,一旦打开quickfix窗口,最后的| silent wincmd p会将焦点切换回编辑窗口

    autocmd! BufWritePost <buffer> silent make % | silent redraw! | silent wincmd p
    

我从未遇到过这种简单设置或^M问题的单一崩溃。

有了这个,你应该在:w之后获得类似的东西:

poor man's syntastic

  • 要将焦点从/移动到quickfix窗口,请使用<C-w>p
  • 要在不使用quickfix窗口的情况下跳转到上一个/下一个错误,请使用:cprevious / :cnext

参考:

:help 'errorformat'
:help 'makeprg'
:help autocmd
:help bufwritepost
:help :silent
:help :redraw
:help :wincmd
:help quickfix

另外,请查看这篇精彩帖子:The Power of Vim