├── LICENSE ├── README.rst ├── ftdetect └── sls.vim ├── ftplugin └── sls.vim ├── salt-vim.spec └── syntax └── sls.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 SaltStack 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =================================== 2 | Vim files for working on Salt files 3 | =================================== 4 | 5 | Installation 6 | ============ 7 | 8 | Using the Pathogen Plugin Manager 9 | --------------------------------- 10 | 11 | The recommended method is to use 12 | `Pathogen `_. 13 | Install Pathogen as described 14 | `here `_, 15 | then do: 16 | 17 | :: 18 | 19 | cd ~/.vim/bundle && \ 20 | git clone https://github.com/saltstack/salt-vim.git 21 | 22 | Using the Vundle Plugin Manager 23 | ------------------------------- 24 | 25 | See 26 | `Vundle `_. 27 | 28 | Manual Method #1: 29 | ----------------- 30 | 31 | :: 32 | 33 | git clone https://github.com/saltstack/salt-vim.git 34 | cd salt-vim && \ 35 | cp -r ftdetect ftplugin syntax ~/.vim/ 36 | 37 | Manual Method #2: 38 | ----------------- 39 | 40 | Alternately, files can be copied into any other directory where Vim looks for 41 | its runtime files, like ``/etc/vim/``. The command ``:set runtimepath`` will 42 | show all such paths. Read ``:help runtimepath`` for more info. 43 | 44 | For all installation methods: 45 | ----------------------------- 46 | 47 | You will also need to specify the following settings in your ``~/.vimrc``: 48 | 49 | .. code-block:: vim 50 | 51 | syntax on 52 | set nocompatible 53 | filetype plugin indent on 54 | 55 | Note: It's possible you may be presented with an error stating something 56 | similar to: 57 | 58 | "E319: Sorry, the command is not available in this version: filetype plugin 59 | indent on" 60 | 61 | If you get this, specify the following settings in your ``~/.vimrc`` instead: 62 | 63 | .. code-block:: vim 64 | 65 | syntax on 66 | set nocompatible 67 | set tabstop=2 68 | set shiftwidth=2 69 | set expandtab 70 | 71 | Too slow? 72 | ========= 73 | 74 | Note that the default yaml highlighting that ships with vim is very slow with 75 | long lines (e.g., ssh keys, or certificates). You might want to switch to a 76 | faster yaml highlighter, like `vim-yaml `_. 77 | 78 | Configuration 79 | ============= 80 | 81 | By default, the syntax file will search for the existence of a Jinja syntax 82 | file (as described in the `Jinja docs`_ or via a `Vim bundle`_) in the 83 | ``runtimepath``, and load that if found. If it is not found, the Django 84 | template syntax file (which is slightly different, but bundled with Vim) will 85 | be used. You can force using either syntax file using the global variable 86 | ``g:sls_use_jinja_syntax``. If it is set, autodetection will be turned off. 87 | 88 | .. _Jinja docs: http://jinja.pocoo.org/docs/integration/#vim 89 | .. _Vim bundle: https://github.com/Glench/Vim-Jinja2-Syntax 90 | 91 | Valid values: 92 | 93 | ``0`` 94 | Use the Django syntax file. 95 | 96 | ``1`` 97 | Use the Jinja syntax file, regardless of whether it exists or not. 98 | 99 | Example section of ``~/.vimrc``: 100 | 101 | .. code-block:: vim 102 | 103 | " Force using the Django template syntax file 104 | let g:sls_use_jinja_syntax = 0 105 | 106 | Files 107 | ===== 108 | 109 | ``syntax/sls.vim`` 110 | Syntax file for editing YAML + Jinja SLS files. 111 | 112 | ``ftplugin/sls.vim`` 113 | Filetype plugin with good default config for SLS files. Configures suitable 114 | wrapping, folding and indenting. Added features: 115 | 116 | - All tabs are converted to spaces. 117 | - Tab key indents by 2 spaces. 118 | - Comments are hardwrapped (with added leading ``#``). 119 | This is done by setting ``formatoptions``. 120 | - key will try to fold/unfold an area. 121 | - Visually selected block might be indented and unindented 122 | by keys ``<`` and ``>``, keeping the visual selection selected. 123 | - Improved indenting of YAML expressions with custom indenting function. 124 | - Visual warning for non-ASCII characters (which are not allowed in YAML). 125 | 126 | ``ftdetect/sls.vim`` 127 | Detect SLS files by the file extension ``.sls``, and ``Saltfile`` files by 128 | an exact filename match. 129 | 130 | Other VIM plugins you might find interesting 131 | ============================================ 132 | 133 | - `Powerline `_ 134 | - `NERDTree `_ 135 | - `Gundo `_ 136 | - `TabMan `_ 137 | - `PythonMode `_ 138 | - `FuzzyFinder `_ 139 | - `CtrlP `_ 140 | -------------------------------------------------------------------------------- /ftdetect/sls.vim: -------------------------------------------------------------------------------- 1 | function! DetectSls() 2 | if !did_filetype() 3 | if match(getline(1), '^#!py') > -1 4 | set ft=python 5 | else 6 | set ft=sls 7 | endif 8 | endif 9 | endfunction 10 | 11 | :au BufNewFile,BufRead *.sls,Saltfile call DetectSls() 12 | -------------------------------------------------------------------------------- /ftplugin/sls.vim: -------------------------------------------------------------------------------- 1 | " Slow yaml highlighting workaround 2 | if exists('+regexpengine') && ('®expengine' == 0) 3 | setlocal regexpengine=1 4 | endif 5 | 6 | " Use two-spaces for indentation 7 | setlocal expandtab 8 | setlocal softtabstop=2 9 | setlocal shiftwidth=2 10 | setlocal commentstring=#%s 11 | 12 | setlocal formatoptions=crl 13 | " r -> don't add comment leader after an Enter 14 | " c -> wrap long comments, including # 15 | " l -> do not wrap long lines 16 | 17 | " indentation 18 | setlocal autoindent 19 | 20 | " This function is from https://gist.github.com/871107 21 | " Author: Ian Young 22 | " 23 | function! GetYamlIndent() 24 | let cnum = v:lnum 25 | let lnum = v:lnum - 1 26 | if lnum == 0 27 | return 0 28 | endif 29 | let line = substitute(getline(lnum),'\s\+$','','') 30 | let cline = substitute(getline(cnum),'\s\+$','','') 31 | let indent = indent(lnum) 32 | let increase = indent + &sw 33 | let decrease = indent - &sw 34 | if line =~ ':$' 35 | return increase 36 | elseif line !~ ':$' && cline =~ ':$' 37 | return decrease 38 | elseif line =~ ':$' 39 | else 40 | return indent 41 | endif 42 | endfunction 43 | 44 | setlocal indentexpr=GetYamlIndent() 45 | 46 | " folding 47 | setlocal foldmethod=indent 48 | setlocal foldlevel=20 " by default do not fold 49 | 50 | 51 | " Visual warning about UTF8 characters in SLS file. 52 | " salt does not like them much, so they should be red 53 | augroup utfsls 54 | autocmd! 55 | highlight UTFsls ctermbg=red guibg=red 56 | match UTFsls /[\x7F-\xFF]/ 57 | autocmd BufWinEnter match UTFsls /[\x7F-\xFF]/ 58 | autocmd InsertEnter match UTFsls /[\x7F-\xFF]/ 59 | autocmd InsertLeave match UTFsls /[\x7F-\xFF]/ 60 | autocmd BufWinLeave call clearmatches() 61 | augroup END 62 | -------------------------------------------------------------------------------- /salt-vim.spec: -------------------------------------------------------------------------------- 1 | Name: salt-vim 2 | Version: 0.0.1 3 | Release: 1%{?dist} 4 | Summary: Vim files for working on Salt files 5 | 6 | Group: Applications/Editors 7 | License: ASL 2.0 8 | URL: https://github.com/saltstack/salt-vim 9 | Source0: https://github.com/saltstack/salt-vim/archive/master.tar.gz 10 | 11 | Requires: vim >= 7 12 | 13 | %description 14 | Vim files for working on Salt files 15 | 16 | %prep 17 | %setup -q -n salt-vim-master 18 | 19 | %build 20 | 21 | %install 22 | mkdir -p %{buildroot}%{_defaultlicensedir}/%{name}-%{version} 23 | mkdir -p %{buildroot}%{_datarootdir}/vim/vimfiles/{syntax,ftdetect,ftplugin} 24 | cp syntax/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/syntax/ 25 | cp ftdetect/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/ftdetect/ 26 | cp ftplugin/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/ftplugin/ 27 | cp LICENSE %{buildroot}%{_defaultlicensedir}/%{name}-%{version} 28 | 29 | %files 30 | %{_datarootdir}/vim/vimfiles/syntax/sls.vim 31 | %{_datarootdir}/vim/vimfiles/ftdetect/sls.vim 32 | %{_datarootdir}/vim/vimfiles/ftplugin/sls.vim 33 | %{_defaultlicensedir}/%{name}-%{version}/LICENSE 34 | %doc 35 | 36 | 37 | 38 | %changelog 39 | * Mon Dec 19 2016 Kai Meyer - 0.0.1-1 40 | - Initial RPM spec 41 | 42 | 43 | -------------------------------------------------------------------------------- /syntax/sls.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Salt States template 3 | " Maintainer: Seth House 4 | " Last Change: 2012 June 20 5 | " 6 | if exists("b:current_syntax") 7 | finish 8 | endif 9 | 10 | if !exists("main_syntax") 11 | let main_syntax = 'yaml' 12 | endif 13 | 14 | let b:current_syntax = '' 15 | unlet b:current_syntax 16 | runtime! syntax/yaml.vim 17 | 18 | let b:current_syntax = '' 19 | unlet b:current_syntax 20 | syntax include @Yaml syntax/yaml.vim 21 | 22 | let b:current_syntax = '' 23 | unlet b:current_syntax 24 | 25 | " Default to look for Jinja syntax file 26 | let s:load_jinja_syntax = 0 27 | let s:search_for_jinja_syntax = 1 28 | if exists("g:sls_use_jinja_syntax") 29 | let s:search_for_jinja_syntax = 0 30 | let s:load_jinja_syntax = g:sls_use_jinja_syntax 31 | endif 32 | if s:search_for_jinja_syntax 33 | let s:jinja_path = findfile("syntax/jinja.vim", &rtp, 1) 34 | if s:jinja_path != "" 35 | let s:load_jinja_syntax = 1 36 | endif 37 | endif 38 | 39 | if s:load_jinja_syntax 40 | syntax include @Jinja syntax/jinja.vim 41 | 42 | syn cluster jinjaSLSBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComment 43 | " Mostly copy/pasted from 44 | " https://github.com/mitsuhiko/jinja2/blob/6b7c0c23/ext/Vim/jinja.vim 45 | syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks 46 | syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks 47 | syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,@jinjaSLSBlocks 48 | else 49 | " Fall back to Django template syntax 50 | syntax include @Jinja syntax/django.vim 51 | 52 | syn cluster djangoBlocks add=djangoTagBlock,djangoVarBlock,djangoComment,djangoComBlock 53 | syn region djangoTagBlock start="{%" end="%}" contains=djangoStatement,djangoFilter,djangoArgument,djangoTagError display containedin=ALLBUT,@djangoBlocks 54 | syn region djangoVarBlock start="{{" end="}}" contains=djangoFilter,djangoArgument,djangoVarError display containedin=ALLBUT,@djangoBlocks 55 | syn region djangoComBlock start="{#" end="#}" contains=djangoTodo containedin=ALLBUT,@djangoBlocks 56 | endif 57 | 58 | syn keyword salt_stateInclude include extend containedin=yamlBlockMappingKey 59 | highlight link salt_stateInclude Include 60 | 61 | syn keyword salt_stateSpecialArgs name names check_cmd listen listen_in onchanges onchanges_in onfail onfail_in onlyif prereq prereq_in require require_in unless use use_in watch watch_in containedin=yamlBlockMappingKey 62 | highlight link salt_stateSpecialArgs Special 63 | 64 | syn keyword salt_stateErrors requires requires_in watches watches_in includes extends containedin=yamlBlockMappingKey 65 | highlight link salt_stateErrors Error 66 | 67 | let g:NERDCustomDelimiters = { 68 | \ 'sls': { 'left': '#' }, 69 | \ } 70 | 71 | let b:current_syntax = "sls" 72 | --------------------------------------------------------------------------------