6 changed files with 336 additions and 0 deletions
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
Copyright (c) 2014 SaltStack |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use |
||||
this file except in compliance with the License. You may obtain a copy of the |
||||
License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed |
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
||||
CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
specific language governing permissions and limitations under the License. |
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
=================================== |
||||
Vim files for working on Salt files |
||||
=================================== |
||||
|
||||
Installation |
||||
============ |
||||
|
||||
Using the Pathogen Plugin Manager |
||||
--------------------------------- |
||||
|
||||
The recommended method is to use |
||||
`Pathogen <https://github.com/tpope/vim-pathogen>`_. |
||||
Install Pathogen as described |
||||
`here <https://github.com/tpope/vim-pathogen#installation>`_, |
||||
then do: |
||||
|
||||
:: |
||||
|
||||
cd ~/.vim/bundle && \ |
||||
git clone https://github.com/saltstack/salt-vim.git |
||||
|
||||
Using the Vundle Plugin Manager |
||||
------------------------------- |
||||
|
||||
See |
||||
`Vundle <https://github.com/gmarik/vundle>`_. |
||||
|
||||
Manual Method #1: |
||||
----------------- |
||||
|
||||
:: |
||||
|
||||
git clone https://github.com/saltstack/salt-vim.git |
||||
cd salt-vim && \ |
||||
cp -r ftdetect ftplugin syntax ~/.vim/ |
||||
|
||||
Manual Method #2: |
||||
----------------- |
||||
|
||||
Alternately, files can be copied into any other directory where Vim looks for |
||||
its runtime files, like ``/etc/vim/``. The command ``:set runtimepath`` will |
||||
show all such paths. Read ``:help runtimepath`` for more info. |
||||
|
||||
For all installation methods: |
||||
----------------------------- |
||||
|
||||
You will also need to specify the following settings in your ``~/.vimrc``: |
||||
|
||||
.. code-block:: vim |
||||
|
||||
syntax on |
||||
set nocompatible |
||||
filetype plugin indent on |
||||
|
||||
Note: It's possible you may be presented with an error stating something |
||||
similar to: |
||||
|
||||
"E319: Sorry, the command is not available in this version: filetype plugin |
||||
indent on" |
||||
|
||||
If you get this, specify the following settings in your ``~/.vimrc`` instead: |
||||
|
||||
.. code-block:: vim |
||||
|
||||
syntax on |
||||
set nocompatible |
||||
set tabstop=2 |
||||
set shiftwidth=2 |
||||
set expandtab |
||||
|
||||
Too slow? |
||||
========= |
||||
|
||||
Note that the default yaml highlighting that ships with vim is very slow with |
||||
long lines (e.g., ssh keys, or certificates). You might want to switch to a |
||||
faster yaml highlighter, like `vim-yaml <https://github.com/stephpy/vim-yaml>`_. |
||||
|
||||
Configuration |
||||
============= |
||||
|
||||
By default, the syntax file will search for the existence of a Jinja syntax |
||||
file (as described in the `Jinja docs`_ or via a `Vim bundle`_) in the |
||||
``runtimepath``, and load that if found. If it is not found, the Django |
||||
template syntax file (which is slightly different, but bundled with Vim) will |
||||
be used. You can force using either syntax file using the global variable |
||||
``g:sls_use_jinja_syntax``. If it is set, autodetection will be turned off. |
||||
|
||||
.. _Jinja docs: http://jinja.pocoo.org/docs/integration/#vim |
||||
.. _Vim bundle: https://github.com/Glench/Vim-Jinja2-Syntax |
||||
|
||||
Valid values: |
||||
|
||||
``0`` |
||||
Use the Django syntax file. |
||||
|
||||
``1`` |
||||
Use the Jinja syntax file, regardless of whether it exists or not. |
||||
|
||||
Example section of ``~/.vimrc``: |
||||
|
||||
.. code-block:: vim |
||||
|
||||
" Force using the Django template syntax file |
||||
let g:sls_use_jinja_syntax = 0 |
||||
|
||||
Files |
||||
===== |
||||
|
||||
``syntax/sls.vim`` |
||||
Syntax file for editing YAML + Jinja SLS files. |
||||
|
||||
``ftplugin/sls.vim`` |
||||
Filetype plugin with good default config for SLS files. Configures suitable |
||||
wrapping, folding and indenting. Added features: |
||||
|
||||
- All tabs are converted to spaces. |
||||
- Tab key indents by 2 spaces. |
||||
- Comments are hardwrapped (with added leading ``#``). |
||||
This is done by setting ``formatoptions``. |
||||
- <Space> key will try to fold/unfold an area. |
||||
- Visually selected block might be indented and unindented |
||||
by keys ``<`` and ``>``, keeping the visual selection selected. |
||||
- Improved indenting of YAML expressions with custom indenting function. |
||||
- Visual warning for non-ASCII characters (which are not allowed in YAML). |
||||
|
||||
``ftdetect/sls.vim`` |
||||
Detect SLS files by the file extension ``.sls``, and ``Saltfile`` files by |
||||
an exact filename match. |
||||
|
||||
Other VIM plugins you might find interesting |
||||
============================================ |
||||
|
||||
- `Powerline <https://github.com/Lokaltog/vim-powerline>`_ |
||||
- `NERDTree <https://github.com/scrooloose/nerdtree>`_ |
||||
- `Gundo <https://github.com/sjl/gundo.vim/>`_ |
||||
- `TabMan <https://github.com/kien/tabman.vim>`_ |
||||
- `PythonMode <https://github.com/klen/python-mode>`_ |
||||
- `FuzzyFinder <https://github.com/vim-scripts/FuzzyFinder>`_ |
||||
- `CtrlP <http://kien.github.com/ctrlp.vim/>`_ |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
function! DetectSls() |
||||
if !did_filetype() |
||||
if match(getline(1), '^#!py') > -1 |
||||
set ft=python |
||||
else |
||||
set ft=sls |
||||
endif |
||||
endif |
||||
endfunction |
||||
|
||||
:au BufNewFile,BufRead *.sls,Saltfile call DetectSls() |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
" Slow yaml highlighting workaround |
||||
if exists('+regexpengine') && ('®expengine' == 0) |
||||
setlocal regexpengine=1 |
||||
endif |
||||
|
||||
" Use two-spaces for indentation |
||||
setlocal expandtab |
||||
setlocal softtabstop=2 |
||||
setlocal shiftwidth=2 |
||||
setlocal commentstring=#%s |
||||
|
||||
setlocal formatoptions=crl |
||||
" r -> don't add comment leader after an Enter |
||||
" c -> wrap long comments, including # |
||||
" l -> do not wrap long lines |
||||
|
||||
" indentation |
||||
setlocal autoindent |
||||
|
||||
" This function is from https://gist.github.com/871107 |
||||
" Author: Ian Young |
||||
" |
||||
function! GetYamlIndent() |
||||
let cnum = v:lnum |
||||
let lnum = v:lnum - 1 |
||||
if lnum == 0 |
||||
return 0 |
||||
endif |
||||
let line = substitute(getline(lnum),'\s\+$','','') |
||||
let cline = substitute(getline(cnum),'\s\+$','','') |
||||
let indent = indent(lnum) |
||||
let increase = indent + &sw |
||||
let decrease = indent - &sw |
||||
if line =~ ':$' |
||||
return increase |
||||
elseif line !~ ':$' && cline =~ ':$' |
||||
return decrease |
||||
elseif line =~ ':$' |
||||
else |
||||
return indent |
||||
endif |
||||
endfunction |
||||
|
||||
setlocal indentexpr=GetYamlIndent() |
||||
|
||||
" folding |
||||
setlocal foldmethod=indent |
||||
setlocal foldlevel=20 " by default do not fold |
||||
|
||||
|
||||
" Visual warning about UTF8 characters in SLS file. |
||||
" salt does not like them much, so they should be red |
||||
augroup utfsls |
||||
autocmd! |
||||
highlight UTFsls ctermbg=red guibg=red |
||||
match UTFsls /[\x7F-\xFF]/ |
||||
autocmd BufWinEnter <buffer> match UTFsls /[\x7F-\xFF]/ |
||||
autocmd InsertEnter <buffer> match UTFsls /[\x7F-\xFF]/ |
||||
autocmd InsertLeave <buffer> match UTFsls /[\x7F-\xFF]/ |
||||
autocmd BufWinLeave <buffer> call clearmatches() |
||||
augroup END |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
Name: salt-vim |
||||
Version: 0.0.1 |
||||
Release: 1%{?dist} |
||||
Summary: Vim files for working on Salt files |
||||
|
||||
Group: Applications/Editors |
||||
License: ASL 2.0 |
||||
URL: https://github.com/saltstack/salt-vim |
||||
Source0: https://github.com/saltstack/salt-vim/archive/master.tar.gz |
||||
|
||||
Requires: vim >= 7 |
||||
|
||||
%description |
||||
Vim files for working on Salt files |
||||
|
||||
%prep |
||||
%setup -q -n salt-vim-master |
||||
|
||||
%build |
||||
|
||||
%install |
||||
mkdir -p %{buildroot}%{_defaultlicensedir}/%{name}-%{version} |
||||
mkdir -p %{buildroot}%{_datarootdir}/vim/vimfiles/{syntax,ftdetect,ftplugin} |
||||
cp syntax/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/syntax/ |
||||
cp ftdetect/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/ftdetect/ |
||||
cp ftplugin/sls.vim %{buildroot}%{_datarootdir}/vim/vimfiles/ftplugin/ |
||||
cp LICENSE %{buildroot}%{_defaultlicensedir}/%{name}-%{version} |
||||
|
||||
%files |
||||
%{_datarootdir}/vim/vimfiles/syntax/sls.vim |
||||
%{_datarootdir}/vim/vimfiles/ftdetect/sls.vim |
||||
%{_datarootdir}/vim/vimfiles/ftplugin/sls.vim |
||||
%{_defaultlicensedir}/%{name}-%{version}/LICENSE |
||||
%doc |
||||
|
||||
|
||||
|
||||
%changelog |
||||
* Mon Dec 19 2016 Kai Meyer <kai@gnukai.com> - 0.0.1-1 |
||||
- Initial RPM spec |
||||
|
||||
|
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
" Vim syntax file |
||||
" Language: Salt States template |
||||
" Maintainer: Seth House <seth@eseth.com> |
||||
" Last Change: 2012 June 20 |
||||
" |
||||
if exists("b:current_syntax") |
||||
finish |
||||
endif |
||||
|
||||
if !exists("main_syntax") |
||||
let main_syntax = 'yaml' |
||||
endif |
||||
|
||||
let b:current_syntax = '' |
||||
unlet b:current_syntax |
||||
runtime! syntax/yaml.vim |
||||
|
||||
let b:current_syntax = '' |
||||
unlet b:current_syntax |
||||
syntax include @Yaml syntax/yaml.vim |
||||
|
||||
let b:current_syntax = '' |
||||
unlet b:current_syntax |
||||
|
||||
" Default to look for Jinja syntax file |
||||
let s:load_jinja_syntax = 0 |
||||
let s:search_for_jinja_syntax = 1 |
||||
if exists("g:sls_use_jinja_syntax") |
||||
let s:search_for_jinja_syntax = 0 |
||||
let s:load_jinja_syntax = g:sls_use_jinja_syntax |
||||
endif |
||||
if s:search_for_jinja_syntax |
||||
let s:jinja_path = findfile("syntax/jinja.vim", &rtp, 1) |
||||
if s:jinja_path != "" |
||||
let s:load_jinja_syntax = 1 |
||||
endif |
||||
endif |
||||
|
||||
if s:load_jinja_syntax |
||||
syntax include @Jinja syntax/jinja.vim |
||||
|
||||
syn cluster jinjaSLSBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComment |
||||
" Mostly copy/pasted from |
||||
" https://github.com/mitsuhiko/jinja2/blob/6b7c0c23/ext/Vim/jinja.vim |
||||
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks |
||||
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks |
||||
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,@jinjaSLSBlocks |
||||
else |
||||
" Fall back to Django template syntax |
||||
syntax include @Jinja syntax/django.vim |
||||
|
||||
syn cluster djangoBlocks add=djangoTagBlock,djangoVarBlock,djangoComment,djangoComBlock |
||||
syn region djangoTagBlock start="{%" end="%}" contains=djangoStatement,djangoFilter,djangoArgument,djangoTagError display containedin=ALLBUT,@djangoBlocks |
||||
syn region djangoVarBlock start="{{" end="}}" contains=djangoFilter,djangoArgument,djangoVarError display containedin=ALLBUT,@djangoBlocks |
||||
syn region djangoComBlock start="{#" end="#}" contains=djangoTodo containedin=ALLBUT,@djangoBlocks |
||||
endif |
||||
|
||||
syn keyword salt_stateInclude include extend containedin=yamlBlockMappingKey |
||||
highlight link salt_stateInclude Include |
||||
|
||||
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 |
||||
highlight link salt_stateSpecialArgs Special |
||||
|
||||
syn keyword salt_stateErrors requires requires_in watches watches_in includes extends containedin=yamlBlockMappingKey |
||||
highlight link salt_stateErrors Error |
||||
|
||||
let g:NERDCustomDelimiters = { |
||||
\ 'sls': { 'left': '#' }, |
||||
\ } |
||||
|
||||
let b:current_syntax = "sls" |
Loading…
Reference in new issue