简体   繁体   English

VIM + Syntastic:如何禁用检查器?

[英]VIM + Syntastic: how to disable the checker?

I'm using Syntastic which is enabled for my HTML files.我正在使用为我的 HTML 文件启用的 Syntastic。 Since I have a very big file with "validator w3" checkers enabled, GVIM or VIM became very slow while saving the file (:w).由于我有一个非常大的文件并且启用了“validator w3”检查器,因此在保存文件 (:w) 时 GVIM 或 VIM 变得非常慢。

Is it possible to toggle syntastic off temporally just for the current session?是否可以仅针对当前会话暂时关闭语法?

Using :SyntasticToggleMode you can toggle Syntastic into passive mode, which will disable auto-checking.使用:SyntasticToggleMode您可以将:SyntasticToggleMode切换到被动模式,这将禁用自动检查。 You can then check a file by running :SyntasticCheck instead.然后,您可以通过运行:SyntasticCheck来检查文件。

For more, see :help syntastic-commands有关更多信息,请参阅:help syntastic-commands

On another note: if Syntastic is slow for you consider trying ale as an alternative.另请注意:如果 Syntastic 速度慢,您可以考虑尝试使用麦芽酒作为替代方案。 Unlike Syntastic it runs asynchronously, so even if it's slow it shouldn't hinder you.与 Syntastic 不同的是,它是异步运行的,因此即使它很慢也不应该妨碍您。

I have disabled Syntastic by default and activate/disable error checking with the following in my .vimrc:我默认禁用了 Syntastic,并在我的 .vimrc 中使用以下内容激活/禁用错误检查:

let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes': [],'passive_filetypes': [] }
nnoremap <C-w>E :SyntasticCheck<CR>

When I need to use error checking I simply hit: ctrl-w E当我需要使用错误检查时,我只需点击: ctrl-w E

Alternative to Jamie and gospes answers, one can disable the checker completely by specifying the checker like so:替代 Jamie 和 gospes 答案,可以通过指定检查器来完全禁用检查器,如下所示:

let g:syntastic_html_checkers=['']

Also make sure the syntastic_check_on_open isn't set to 1, which will countermand the above line:还要确保syntastic_check_on_open未设置为 1,这将syntastic_check_on_open上述行:

let g:syntastic_check_on_open = 0

You could turn Syntastic off for the entire session (as answered by Jamie Schembri ), but if it's just a problem with the one "very big file", you may want to disable just the one buffer.您可以在整个会话期间关闭 Syntastic(如Jamie Schembri所回答),但如果这只是一个“非常大的文件”的问题,您可能只想禁用一个缓冲区。

A few of the files I work on at my job are hopelessly non-PSR compliant.我在工作中处理的一些文件无可救药地不符合 PSR。 Most work just fine.大多数工作都很好。 I was looking for functionality to disable Syntastic for just those problem files.我正在寻找仅针对那些问题文件禁用 Syntastic 的功能。 A simpler form of the ' SyntasticDisableToggle ' solution outlined by the primary contributor works for me:主要贡献者概述的“ SyntasticDisableToggle ”解决方案的更简单形式对我有用

"disable syntastic on a per buffer basis (some work files blow it up)
function! SyntasticDisableBuffer()
    let b:syntastic_skip_checks = 1
    SyntasticReset
    echo 'Syntastic disabled for this buffer'
endfunction

command! SyntasticDisableBuffer call SyntasticDisableBuffer()

Because this doesn't affect other buffers, I can keep using this awesome plugin for any other (partially) compliant files I have open.因为这不会影响其他缓冲区,所以我可以继续使用这个很棒的插件来处理我打开的任何其他(部分)兼容的文件。

This doesn't directly address the question, but can help beyond the current session.这不会直接解决问题,但可以在当前会话之外提供帮助。 If you have a file that you must edit often but which you know that you will always want to disable Syntastic on (eg it has thousands of errors and you intend not to fix them, and leaving it on results in UI slowdown), then permanently blacklisting it is very convenient.如果您有一个必须经常编辑的文件,但您知道您将始终希望禁用 Syntastic(例如,它有数千个错误并且您不打算修复它们,并且将其保留会导致 UI 速度变慢),那么永久加入黑名单很方便。

To do this, use the syntastic_ignore_files option.为此,请使用syntastic_ignore_files选项。 It's tucked away in the help, but you can use regexes with this feature to blacklist files.它隐藏在帮助中,但您可以使用具有此功能的正则表达式将文件列入黑名单。

                                                    'syntastic_ignore_files'
Default: []
Use this option to specify files that syntastic should never check.  It's a
list of regular-expression patterns.  The full paths of files (see ::p) are
matched against these patterns, and the matches are case sensitive. Use \c
to specify case insensitive patterns.  Example:
    let g:syntastic_ignore_files = ['\m^/usr/include/', '\m\c\.h$']

The following settings worked for me.以下设置对我有用。

let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes':   [],'passive_filetypes': [] }
noremap <C-w>e :SyntasticCheck<CR>
noremap <C-w>f :SyntasticToggleMode<CR>

Ctrl-w + e shall enable checking
Ctrl-w + f shall disable checking 

To disable warnings use: 
let g:syntastic_quiet_messages={'level':'warnings'}

Similarly to those mentioned by a few others, here's a vimrc segment that will turn off Syntastic by default, but maps a button (here, F10) to check the current file, and uses the same button as a toggle to turn off the checks.与其他一些人提到的类似,这里有一个 vimrc 段,默认情况下会关闭 Syntastic,但映射一个按钮(这里是 F10)来检查当前文件,并使用与切换相同的按钮来关闭检查。 It's a little slow, but works.它有点慢,但有效。

let g:syntastic_check_on_open = 0                                                                                 
let g:syntastic_check_on_wq = 0
let g:syntastic_mode_map = {'mode':'passive'}
nnoremap <F10> :SyntasticCheck<CR> :SyntasticToggleMode<CR> :w<CR>

Another option to turn off checking for a single buffer (regardless of filetype) is to use :let b:syntastic_mode="passive" .关闭检查单个缓冲区(无论文件类型如何)的另一个选项是使用:let b:syntastic_mode="passive" Since it isn't a toggle, it will work even if the buffer is currently in passive mode.由于它不是切换,即使缓冲区当前处于被动模式,它也能工作。

If you want to temporarily turn off checking of all filetypes in all buffers, you can use :bufdo let b:syntastic_mode="passive" .如果要暂时关闭对所有缓冲区中所有文件类型的检查,可以使用:bufdo let b:syntastic_mode="passive" I have setup mappings to turn off/on checking of all buffers:我有设置映射来关闭/打开所有缓冲区的检查:

nnoremap <leader>sN :bufdo let b:syntastic_mode="passive"<cr>
nnoremap <leader>sY :bufdo unlet b:syntastic_mode<cr>

This is particularly helpful when doing :wqa with a lot of open buffers.这在使用大量开放缓冲区执行:wqa时特别有用。

Thanks for Steven Lu , I can ignore the files of Ansible Roles , now.感谢Steven Lu ,我现在可以忽略Ansible Roles的文件了。

" ignore files of Ansible Roles.
let g:syntastic_ignore_files = ['\m^roles/']

I'm using Ale and Syntastic mainly because Rust Ale support is not very good yet.我使用 Ale 和 Syntastic 主要是因为 Rust Ale 支持还不是很好。 In my case I'm using vim-plug package manager, I setup so that it will not enable any of these automatically.在我的情况下,我使用 vim-plug 包管理器,我设置为它不会自动启用任何这些。 I use a toggle strategy instead.我改用切换策略。

In my case I want Ale by default, and Syntastic for Rust在我的情况下,我默认需要 Ale,而 Syntastic for Rust

In plugin portion of vimrc I did this在 vimrc 的插件部分我做了这个

Plug 'w0rp/ale', { 'on': 'ALEToggle' }
Plug 'vim-syntastic/syntastic', { 'on': 'SyntasticToggleMode' }

Afterwards I set a bind to enable linter, (I use l as mnemoic for linter)之后我设置了一个绑定以启用 linter,(我使用 l 作为 linter 的助记符)

nnoremap <leader>l :ALEToggle<CR>

For Rust I override the same bind对于 Rust,我覆盖了相同的绑定

au FileType rust noremap <buffer> <leader>l :SyntasticToggleMode<CR>

Also I had to remove the statusline stuff from my vimrc otherwise I get errors when loading it with Syntastic disabled此外,我必须从 vimrc 中删除状态行内容,否则在禁用 Syntastic 的情况下加载它时会出错

" Syntastic stuff
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*

let g:rustfmt_autosave = 1
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
" Syntastic stuff

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM