Install Syntastic for Vim on Mac

Nov 18, 2016 Vim 中文版

If you love Vim and want to use it like a modern IDE, you shouldn’t omit Syntastic, a powerful syntax checker. Not only it provides syntax checking for various of programming languages, but allows you to check coding style by integrating it with other tools (like flake8 for PEP 8). So, this post is about how to install and use it.



Prerequisite

To install plugins for Vim, I usually use Vundle, an easy-to-use plugin manager. And I will use it in this tutorial, so you can start to use it today.

Install Syntastic

Let’s install Syntastic through Vundle. First, open your Vim configuration (/etc/vimrc or ~/.vimrc), and then add the plugin name and related settings into it. For example:

" skip some content ... "

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'gmarik/Vundle.vim'

" Add Syntastic plugin here "
Plugin 'scrooloose/syntastic'

call vundle#end()
filetype plugin indent on

" skip some content ... "

" Drop Syntastic settings at the end of the config file "
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

You can specify your favorite checkers by adding this:

" Use specific checkers, and don't forget to install them "
let g:syntastic_<filetype>_checkers = ['<checker-name>']

" For example: replace the default Python checker with flake8 and pylint "
let g:syntastic_python_checkers = ['flake8', 'pylint']

What’s more, you can change the error symbol and the warning symbol:

let g:syntastic_error_symbol = 'Put a symbol or an emoji you like'
let g:syntastic_warning_symbol = 'Put a symbol or an emoji you like'

After modification to Vim config, install it by executing the command in Vim:

:PluginInstall

Or, drop the command in your terminal:

vim +PluginInstall +qall


Use Syntastic

Actually, there is nothing else you should do. Every time you modify a file and save it, Syntastic will automatically create a window and show related information for you. If you want more detailed information, just execute the command:

:help syntastic




You might also like:




If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)

zeckli.devforgalaxy@gmail.com   © 2015-2019 zeckli, thanks to Jekyll and GitHub.