127

I'm using Syntastic which is enabled for my HTML files. Since I have a very big file with "validator w3" checkers enabled, GVIM or VIM became very slow while saving the file (:w).

Is it possible to toggle syntastic off temporally just for the current session?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Yves Lange
  • 3,914
  • 3
  • 21
  • 33

10 Answers10

178

Using :SyntasticToggleMode you can toggle Syntastic into passive mode, which will disable auto-checking. You can then check a file by running :SyntasticCheck instead.

For more, see :help syntastic-commands

On another note: if Syntastic is slow for you consider trying ale as an alternative. Unlike Syntastic it runs asynchronously, so even if it's slow it shouldn't hinder you.

Jamie Schembri
  • 6,047
  • 4
  • 25
  • 37
  • 1
    Is there any way to create a single alias or map a key to toggle this? I.e., `:error` or Ctrl+Shift/Alt+e toggles between `:SyntasticCheck` and `:SyntasticToggleMode`. – cintron Feb 09 '15 at 19:24
  • 2
    You can create an alias like this in the .vimrc: `:command Sd SyntasticToggleMode` Then in vi press :Sd and it will disable syntastic. More info on how to do that here: http://stackoverflow.com/questions/3878692/aliasing-a-command-in-vim – Eric Leschinski May 26 '15 at 21:56
  • 2
    nice. heres a mapping to F6 if someone want to use it `silent! nmap :SyntasticToggleMode` – random-forest-cat May 26 '16 at 19:26
97

I have disabled Syntastic by default and activate/disable error checking with the following in my .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

Henry Henrinson
  • 5,203
  • 7
  • 44
  • 76
gospes
  • 3,819
  • 1
  • 28
  • 31
  • This is quite handy, thanks .. I have added the idea to my config. +1 – jdt Apr 17 '14 at 03:41
  • 4
    I've added this to my `.vimrc` aswell. However if i press **Ctrl-w E** Syntastic pops up for a second and vanishes again. Any ideas what's going wrong and/or how to track this down? – Anticom Nov 27 '15 at 07:59
  • I think the mapping shouldn't have :SyntasticToggleMode, removing that should fix your issue @Anticom. – Achal Dave Feb 25 '16 at 21:23
  • @AchalDave Didn't fix it for me. – Anticom Feb 26 '16 at 09:26
  • Hm, no idea. Here's what my syntastic settings look like: https://github.com/achalddave/dotfiles/blob/622f991617887fc7dc95ac0e5018c92c6b9c871e/vim/.vimrc#L170 – Achal Dave Feb 26 '16 at 20:59
  • Seems like [the e must be lowercase](https://stackoverflow.com/a/34015088/2550406) or it wouldn't work. Also, need to make sure to release control before pressing `e` – lucidbrot Oct 28 '21 at 19:25
  • To hide it again, we can do the same for a different key, e.g. `nnoremap :SyntasticReset` – lucidbrot Oct 28 '21 at 19:34
34

Alternative to Jamie and gospes answers, one can disable the checker completely by specifying the checker like so:

let g:syntastic_html_checkers=['']

Also make sure the syntastic_check_on_open isn't set to 1, which will countermand the above line:

let g:syntastic_check_on_open = 0
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
chutsu
  • 13,612
  • 19
  • 65
  • 86
11

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.

A few of the files I work on at my job are hopelessly non-PSR compliant. Most work just fine. I was looking for functionality to disable Syntastic for just those problem files. A simpler form of the 'SyntasticDisableToggle' solution outlined by the primary contributor works for me:

"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.

Community
  • 1
  • 1
ssteele
  • 135
  • 1
  • 7
7

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 (e.g. 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.

To do this, use the syntastic_ignore_files option. 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$']
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • 1
    Works great! Not what the question was asking for though. Here's a +1 for being useful. – bschlueter May 10 '16 at 23:10
  • Thanks, I used this to prevent checking of temporary bash files when editing command lines with C-X C-E: `let g:syntastic_ignore_files = ['\m^/tmp/bash-.*'`] – Anthony Geoghegan Oct 25 '20 at 13:39
7

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'}
koshyg
  • 121
  • 2
  • 5
6

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. 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>
nothijngrad
  • 61
  • 1
  • 2
4

Another option to turn off checking for a single buffer (regardless of filetype) is to use :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". 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.

Mark Grimes
  • 547
  • 4
  • 8
0

Thanks for Steven Lu, I can ignore the files of Ansible Roles, now.

" ignore files of Ansible Roles.
let g:syntastic_ignore_files = ['\m^roles/']
Community
  • 1
  • 1
Chu-Siang Lai
  • 2,658
  • 1
  • 24
  • 21
0

I'm using Ale and Syntastic mainly because Rust Ale support is not very good yet. In my case I'm using vim-plug package manager, I setup so that it will not enable any of these automatically. I use a toggle strategy instead.

In my case I want Ale by default, and Syntastic for Rust

In plugin portion of vimrc I did this

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)

nnoremap <leader>l :ALEToggle<CR>

For Rust I override the same bind

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

" 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

geckos
  • 5,687
  • 1
  • 41
  • 53