Coder Social home page Coder Social logo

salt-vim's Introduction

Vim files for working on Salt files

Installation

Using the Pathogen Plugin Manager

The recommended method is to use Pathogen. Install Pathogen as described here, then do:

cd ~/.vim/bundle && \
git clone https://github.com/saltstack/salt-vim.git

Using the Vundle Plugin Manager

See 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:

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:

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.

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.

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:

" 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

salt-vim's People

Contributors

arthurzenika avatar basepi avatar cwood avatar davidjb avatar dewingok avatar ingwa avatar jfindlay avatar jmatth avatar kremso avatar malept avatar mariodpros avatar mgwilliams avatar nbirnel avatar rominf avatar roxit avatar terminalmage avatar thatch45 avatar tony avatar whiteinge avatar zackhsi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salt-vim's Issues

nicer install / update resistant:

It would be a little more useful if e.g. after:

cd ~/.vim/
git clone https://github.com/saltstack/salt-vim.git

symlinks are created for config files instead of copies:

cd salt-vim
ls */* | xargs -I{} ln -s ../salt-vim/{} ../{}

Or manual way:

ln -s ../salt-vim/ftdetect/sls.vim ~/.vim/ftdetect/sls.vim
ln -s ../salt-vim/ftplugin/sls.vim ~/.vim/ftplugin/sls.vim
ln -s ../salt-vim/syntax/sls.vim ~/.vim/syntax/sls.vim

Bests

salt-vim with Syntastic?

Is there support to enable syntastic checking for SLS files? I haven't been able to find a compatible linter for it. js-yaml is close, but it obviously chokes on Jinja.

Has anyone been able to get this working?

question: disable folding? Overriding sls.vim's "foldmethod=indent"

Having a difficult time overriding the folding set by PR #1:

" folding
setlocal foldmethod=indent
setlocal foldlevel=6  " by default do not fold

I use a very vanilla vim, but folding occurs, appears as:

verify-docker-tcp-server:
  cmd.run:
    # although docker service is 'started', we must await a few seconds until tcp port is bound
    - name: |
        timeout 10 bash -c '\
            until curl --verbose --fail --show-error --silent \
+--------  4 lines: https://localhost:2376/images/json \----------------------------------------------
            do
                sleep 1
            done'

If I try to disable this by .vimrc:

set foldmethod=manual

These settings are not honored when opening any .sls file, they remain as set in sls.vim, when i type ":set foldmethod" on any non-.sls file, foldmethod=manual, but opening a .sls sets foldmethod=indent again.

small parser bug/ feature request when using multiple loops with { } ?

Hello,

I got a file with a nice onliner for setting variables from pillar to enhance like:

{%- do environments[environment].update ({ 'jenkins': { 'port': '1' + port['environment'][environment]['port'] + '00' + '6' }}) %}

and the closing loops written as }} are marked red because the parser identifies it as closing saltstack tag which is missing the opening tag instead of 2 independent ending loop marker.

If this is not too complicated it would be nice there could a fix ?

Bests

vim reports "Invalid expression" in syntax/sls.vim

I'm using vim-8.2.2607.

When editing a sls file, vim complains about the following "Invalid expression" on startup:

# vi whatever.sls
Error detected while processing /etc/vimrc[42]../usr/share/vim/vim82/syntax/syntax.vim[42]..BufRead Autocommands for "*.sls"..function DetectSls[5]..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>3_SynSet[25]..script /home/cb/.vim/syntax/sls.vim:
line   67:
E15: Invalid expression: {
line   68:
E10: \ should be followed by /, ? or &
line   69:
E10: \ should be followed by /, ? or &
Press ENTER or type command to continue

Can you please fix this?

mako python code upsets syntax coloring

I realize you maybe not want to support mako in slses but if you still want to here is a short snippet of code that upsets the syntax coloring:

<%
out.append("{{{{ record('{0}', 'SSHFP', '{1}') }}}}".format(host,line))

# the following line starts red
out.append("{{{{ record('piro', 'SSHFP', '{0}') }}}}".format(line))

%>
${"\n".join(out)}

Looks like this:

screen shot 2016-11-09 at 09 nov 12 33 10

This is mako code that generates jinja templates, hence the amount of braces.

auto-indentation broken

when indenting using gg=G, the indentation does what its documented to do.

Every ':' the new line gets indented two more spaces. the problem is it never goes back.

base:
  'host1':
    - services.apache
    'host2':
      - services.apache

..it just never removes the two spaces again when it should.

Evil Mode

Please mention evil-mode compatibility in the readme?

I'm an eviller, myself. I just love lisp too much.

In every other respect's vim's superior, and evil suits.

How to make a string in single quotes is highlighted as blue?

I would like to use single quotes for pillar.get or concatenate strings:

jinja2 string in vim

but also want to highlight the string as blue like in the second line.

How to do that?

My ~/.vimrc:

set backup
let day = strftime("%Y-%m-%d")
let user = substitute(system('whoami'), '\n', '', '')
if user == 'root'
    let backupdir = "/var/root/.vim/backup/".day
else
    let backupdir = $HOME."/.vim/backup/".day
endif
silent! let xyz = mkdir(backupdir, "p")
let cmd = "set backupdir=".backupdir
execute cmd
let time = strftime(".%H:%M:%S")
let cmd = "set backupext=".time
execute cmd

syntax on
set number
set background=dark
let g:solarized_termcolors = 256
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
let g:solarized_termtrans = 1
colorscheme solarized

autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab

"autocmd FileType rst set syntax=rest

set clipboard=unnamed
execute pathogen#infect()
let g:SuperTabDefaultCompletionType = "context"

filetype off

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

Bundle 'gmarik/vundle'

" powerline

" end of powerline

set nocompatible
filetype plugin indent on
autocmd BufRead,BufNewFile *.jinja2 set filetype=sls.jinja2

nnoremap <F6> :GundoToggle<CR>

" ultisnips
let g:UltiSnipsSnippetsDir ="~/.vim/bundle/ultisnips/UltiSnips"
let g:UltiSnipsListSnippets = "<c-j>"
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" end of ultisnips

au BufNewFile *.jinja2 so ~/.vim/header/jinja_header.txt
au BufNewFile *.py so ~/.vim/header/py_header.txt
au BufNewFile *.sls so ~/.vim/header/sls_header.txt

let mapleader = ","
set runtimepath^=~/.vim/bundle/ctrlp.vim
let g:ctrlp_map = '<leader>f'
let g:ctrlp_prompt_mappings = {
    \ 'AcceptSelection("e")': ['<c-v>', '<2-LeftMouse>'],
    \ 'AcceptSelection("v")': ['<cr>', '<RightMouse>'],
    \ }
" airline
set laststatus=2
" end of airline

" highlight excess line length (79)
autocmd Filetype py rst textwidth=79
set colorcolumn=+1

" go
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
" end of go

" neocomplete
" let g:neocomplete#enable_at_startup = 1
" end of neocomplete

" disable folding
set nofoldenable
" end of disable folding

" disable matchparen
" let loaded_matchparen=1
" end of disable matchparen

License?

I'd like to make a code-related pull request, but I can't find a license in the repository.

Sublime Text Support

Vim is good. But sometimes I just need to use something else rather than spent an hour learning more vim-fu.
Different syntax highlighting between editors is very annoying.

I'll eventually find time to write this myself if no one else cares... but I know someone smarter than me in both Sublime Text knowledge and Salt knowledge would be able to do it a lot sooner, like months sooner :)

Fold/unfold all?

Is it possible to toggle fold/unfold all sections of a state file with one command? Scrolling to each fold and pressing 'space' on many folds is time consuming. TIA!

wrong autoindent on copy/paste

When copying and pasting an already indented block, like:
mysql:
__service:
__- running

it will add extra tabs and will look like this:
mysql:
____service:
________- running

Complete states

It would be nice to complete state names and arguments.

I propose to add variable:

set salt_minion=localhost

And then gather completions with:

salt $salt_minion sys.state_argspec

add filetype plugin on to docs

Would be useful to add ":filetype plugin on" intruction to docs.

Would save some time for novice vim users :D.

Other than that, great project! Thanks.

UTF-8 warning for salt problems

Hello,

The function is very nice.
But would'nt it be better to set then the default behavior that vim didn't save them in the wrong format?

like here:
http://automatthias.wordpress.com/2006/07/18/vim-utf-8-and-iso-8859-2/

I have added in ~/.vim/ftplugin/sls.vim:

setlocal fileencoding=latin1

and now it looks nice in the file:

# file telescope/init.sls
telescope/init.sls: ASCII text, with very long lines
# vi telescope/init.sls 
< adding umlauts  äöüß>
# file telescope/init.sls
telescope/init.sls: ISO-8859 text, with very long lines

There is only still the red warning in the interface because editing is done in UTF-8 locale which can then be removed ?

Dog-slow in sls with long lines

When there are long lines in the sls, whole vim becomes very unresponsive and slow. I have an sls where multiple ssh public keys are listed and the only way I can edit that is by setting set ft=none.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.