Skip to content

Instantly share code, notes, and snippets.

@ventz
Forked from thikade/vim_syntaxchecker.md
Created February 27, 2023 04:47
Show Gist options
  • Save ventz/8c7f05e84a89ccdd19e73d1b766ff987 to your computer and use it in GitHub Desktop.
Save ventz/8c7f05e84a89ccdd19e73d1b766ff987 to your computer and use it in GitHub Desktop.
vim syntax checker / syntastic yamllint

Getting vim yaml linter to work:

  1. Install syntastic vim plugin (as of vim 7.4.x no plugin manager is required anymore!)
    mkdir -p ~/.vim/pack/$USER/start/
    cd ~/.vim/pack/$USER/start/
    git clone https://github.com/vim-syntastic/syntastic.git
    
  2. Install yamllint: pip3 install yamllint
  3. Configure yamllint:
  4. Config and activate plugin checkers in vimrc – see attached vimrc
  5. Open a file x.yml and edit away, and save!
  6. To see what Syntastic knows about this file by using the command :SyntasticInfo

Links:

https://github.com/vim-syntastic/syntastic https://github.com/vim-syntastic/syntastic/blob/master/doc/syntastic-checkers.txt https://github.com/vim-syntastic/syntastic/blob/master/doc/syntastic-checkers.txt

set t_Co=256
set nocompatible
"attempt to determine the file type
filetype indent plugin on
""syntax highlighting
if &t_Co > 2 || has("gui_running")
syntax on
endif
"command-line completion
set wildmenu
"shows partial commands
set showcmd
"highlight searches
set hlsearch
set vi+=n
"case insensitive search
set ignorecase
set smartcase
set incsearch
"displays cursor position
set ruler
set laststatus=2
"dialogue save changed instead of failing
set confirm
"display relative numbers
set number
set relativenumber
set numberwidth=3
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
"use spaces instead of tabs
set shiftwidth=4
set softtabstop=4
set expandtab
"add these lines to your vimrc to configure syntastic & yamllint
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1 " automatically load errors into the location list
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1 " check for errors when a file is loaded
let g:syntastic_check_on_wq = 0
let g:syntastic_yaml_checkers = [ "yamllint" ]
let g:syntastic_quiet_messages = { "type": "style" }
---
rules:
braces: enable
brackets: enable
colons: {max-spaces-before: 0, max-spaces-after: 8}
commas: enable
comments:
level: warning
comments-indentation:
level: warning
document-end: disable
document-start:
level: warning
empty-lines: enable
empty-values: enable
hyphens: enable
indentation: enable
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: enable
new-lines: enable
octal-values: enable
quoted-strings: disable
trailing-spaces: enable
truthy:
level: warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment