首页 文章

关于Vim的一些JSHint / Syntastic问题

提问于
浏览
1

我正在使用Vim with Syntastic和JSHint,还有一些我想解决的小问题 .

  • 每当我修改一行文本中的最后一个字符并保存(:w)时,我会在文本之前(有时)消失之后暂时看到"^M" flash . 有时会粘在一起,我必须手动删除它 . 这有什么用处,我该如何预防呢?

  • 如果quickfix视图中有错误,如何在quickfix视图和Vim编辑器窗口之间切换焦点?

  • Vim可能每分钟崩溃一次,而且我非常讨厌 . 该错误通常读取"Vim: Caught deadly signal ABRT Vim: Finished. [1]6099 abort vi gulpfile.js"如何防止这种情况?

这是我的.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

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

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

    jshint的

    • errorformat
    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

相关问题