Giter Site home page Giter Site logo

vim-ansible-yaml's Introduction

vim-ansible-yaml

Maintainer wanted!

I don't have time to maintain this and haven't used Ansible in quite some time. If anyone would like to come in as a collaborater and maintain it, feel free to open up an issue!

Also, if you feel like this bundle isn't quite what you'd want, check out ansible-vim by @pearofducks!


Adds additional syntax highlighting and fixes indentation for Ansible's dialect of YAML.

Allows a user-specified mapping in normal mode to search the ansible docs for the keyword underneath the current cursor position. See below for configuration.

Ansible YAML files are detected based on the presence of a modeline or a structure following Ansible's Playbook Best Practices. For details, see the Detection section below.

Install

Using Vundle

  1. Add the following to your .vimrc where other bundles are located:

     Bundle 'chase/vim-ansible-yaml'
    
  2. Run from command line:

     $ vim +BundleInstall
    

Using pathogen

  1. Check out the repository into your bundle path:

     $ cd ~/.vim/bundle
     $ git clone git://github.com/chase/vim-ansible-yaml.git
    
  2. Install the help file. (Repeat this step if you get an updated version.) From inside vim,

    :Helptags

Normal

  1. Check out the repository and copy the following to .vim/ directory or any other run time path, keeping their directory structure intact:

     doc/ansible.txt
     ftdetect/ansible.vim
     syntax/ansible.vim
     syntax/include/jinja.vim
     syntax/include/yaml.vim
     indent/ansible.vim
    
  2. Install the help file. From inside vim, :helptags ~/.vim/doc.

Detection

You can tell vim to recognize a file as Ansible by adding a modeline near the top or bottom of the file:

# vim:ft=ansible:

A file is recognized as an Ansible YAML file, and its filetype is set to ansible, if

  1. The file extension is .yml or .yaml
  2. AND one of the following conditions holds:
  3. The file is somewhere under a directory named roles.
  4. The file is in the same directory as a directory (or file) named group_vars, host_vars, or roles.

Configuration

All configuration options will live under g:ansible_options.

ignore_blank_lines

If you define

let g:ansible_options = {'ignore_blank_lines': 0}

in your vimrc file, then the indent function will remove all indent after a blank line. The default behavior is to ignore blank lines when calculating the indent of the current line. This is helpful if your style is to insert blank lines, as in

tasks:
  - name: Say hello.
    command: echo Hello, world.

  - name: Say good night, Dick.
    command: echo Good night, Dick.

If g:ansible_options is not defined, or if the ignore_blank_lines key is not present, or the value is not 0, then the indent function uses the default behavior.

documentation_mapping

The documentation_mapping option enables setting a custom mapping to search the Ansible documentation for the word under the cursor.

It can be enabled as such: let g:ansible_options = {'documentation_mapping': '<C-K>'} - which would bind Control-K to perform the search.

Thanks

Benji Fisher helped out a great amount as a maintainer, thanks a ton!

A huge thanks to Igor Vergeichik and Nikolai Weibull for their work on the YAML syntax that this bundle uses.

Also, thank you, Armin Ronacher, for the simple and effective Jinja syntax file.

vim-ansible-yaml's People

Contributors

benjifisher avatar certifiedloud avatar chase avatar dohsimpson avatar erikzaadi avatar gabesullice avatar gundalow avatar jeremywrnr avatar jorgeegomez avatar komuta avatar pearofducks avatar serialdoom avatar undergreen 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

vim-ansible-yaml's Issues

Indenting expression needs to be improved

Given the playbook from http://docs.ansible.com/playbooks_intro.html:


---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
  - name: write the apache config file
    template: src=/srv/httpd.j2 dest=/etc/httpd.conf
    notify:
    - restart apache
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
  handlers:
    - name: restart apache
      service: name=httpd state=restarted

gg=G results in:


---
- hosts: webservers
  vars:
  http_port: 80
  max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
    - name: write the apache config file
      template: src=/srv/httpd.j2 dest=/etc/httpd.conf
      notify:
      - restart apache
      - name: ensure apache is running (and enable it at boot)
        service: name=httpd state=started enabled=yes
        handlers:
        - name: restart apache
          service: name=httpd state=restarted

The indenting code seems to mix expressions that rely on different magic settings for Vim:
https://github.com/chase/vim-ansible-yaml/blob/master/indent/ansible.vim#L40-51

E.g. ':\s*[>|]?$' should be '\v:\s*[>|]?$' probably, and all patterns should explicitly state what mode to use, e.g. via \v.

But that is not enough to fix this.

I've tried to address this, and the result would be:


---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
  - name: write the apache config file
    template: src=/srv/httpd.j2 dest=/etc/httpd.conf
    notify:
    - restart apache
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
  handlers:
  - name: restart apache
    service: name=httpd state=restarted

This changes (decreases) the indentation of the handlers list,
which is in line with the other lists.

Since I am new to Ansible I might be missing something, and probably there are different styles of indenting list entries?

However, keeping them in line to the start of the list made it easier to handle.
If I remember correctly it would not be possible to handle gg=G then in all cases, because the previous lines would have been indented already.

I will provide a PR for this.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/11556485-indenting-expression-needs-to-be-improved?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Add folding support

I'd really like to automatically fold the top level of my ansible .yml files. Could you please add folding support?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/3664814-add-folding-support?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Create a release

Although I can push to this repo, I do not seem to have permission to create releases. (I do not see a settings option in the sidebar.)

I do not have any immediate plans for this project, so I think this is a good time to declare v1.0.

Add snippets for SnipMate or UltiSnip plugins.

It would be nice to be able to type something like

  file<Tab>

and have it automatically expand to show the arguments of the file module. This functionality is provided by various vim plugins, including SnipMate and UltiSnips. SnipMate has more stars on GitHub, but UltiSnips is actively maintained.

All we have to do is provide snippet definitions. Unfortunately, the two plugins use different formats.

As a first pass, I created the file extract_snippets.vim:

let modline = search('^module:')
if !modline
  q
endif
let module = matchstr(getline(modline), '\S\+\ze\s*$')
let options = []
/^options:/;/^\S/g/^  \S/call add(options, matchstr(getline('.'), '\S.*\ze:\s*$'))
e /tmp/snippets.vim
$put=''
put= 'snippet ' . module
let tab = "\<Tab>"
let i = 1
put= tab . module . ':'
for opt in options
  put= tab . tab . opt . '=${' . i . '}'
  let i = i + 1
endfor
wq

Then, from the directory ansible/1.7.2/share/ansible, I ran (adapted from :help 26.4)

for file in */*; do
  vim -e -s $file < /tmp/extract_snippets.vim;
done

That works pretty well, except that some modules have the pseudo-option "others", meaning that they also accept all the options of the file module. So I went and fixed those by hand.

This script makes SnipMate-compatible snippets.

Before I commit any snippet files to the project, I want to spend a few days testing, and maybe make some refinements. A few ideas:

  1. Decide whether to be compatible with SnipMate or UltiSnips.
  2. Perhaps omit the modules that do not have any options.
  3. Perhaps use a one-line format for modules that have only one or two options.
  4. Provide defaults, or maybe defaults and alternatives.

Once we have ironed out the details, we should make it easy to reproduce, both for the sake of those who have custom Ansible modules and for the maintainers of this project, as Ansible is updated.

Vim freezes with heavy CPU usage when opening Ansible files

Revert back to the previous commit fixes this issue. I'll try and see if this is related to something else in my .vimrc


Solution

Ensure that ``regexpengineis set to0`.
The new YAML syntax is not compatible with the old engine, when `regexpengine` or `re` is set to 0.

Double-quoted multi-lines lines

Top file is filetype ansible, bottom file is filetype yaml. The top file shows the problem with double-quoted multiple lines:
vim-ansible-yaml

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/13295896-double-quoted-multi-lines-lines?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

ftdtect error on files outside of roles directory

On vim 7.3, trying to edit a file on /etc/ansible results in this warning:

Too many arguments for function: glob

Removing an extra "1" on vim-ansible-yml/ftdetect/ansible.vim now results in

Argument of map() must be a List or Dictionary

Which, according to vimdoc, is correct: glob returns a string.

Invalid expression with vim-fugitive

Thanks for the plugin

When I try to execute a :Gdiff with vim-fugitive in an ansible file, I get this error

Error detected while processing /Users/nzac/.vim/bundle/vim-ansible-yaml/syntax/ansible.vim:
line   48:
E121: Undefined variable: main_syntax
E15: Invalid expression: main_syntax == 'ansible'

Vim Version:

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 15 2016 15:54:04)
MacOS X (unix) version
Included patches: 1-1090
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         -gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1   
Linking: /usr/bin/clang   -L. -L/usr/local/lib -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -F/usr/local/Cellar/python/2.7.11/Frameworks -framework Python   -lruby.2.0.0 -lobjc

Anything

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30085416-invalid-expression-with-vim-fugitive?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

YAML highlighting breaks on bar characters

Heya, cool idea for this plugin, thanks for creating it!

I've found that with it installed and the filetype detection correctly working, the bar character is breaking my YAML syntax highlighting. It's a pretty common convention to use bars in task names since some of Ansible's own output formatting uses them too. Here's an example:

- name: Elasticsearch | Set ownership of data directory
  file: path={{ elasticsearch['data_dir'] }} owner=elasticsearch group=elasticsearch
  sudo: true
  tags:
    - elasticsearch

On my setup, the Jinja highlighting is working for the {{ }} (sweet!), but unfortunately everything else after the bar is not highlighted correctly.

I'm not schooled in the arts of Vim syntax definitions, so apologies for not trying to fix -- I'll take a stab if I have some time to learn up. Hopefully the example is enough to reproduce, let me know if any more detail about my setup is helpful.

YAML flow mappings are not highlighted correctly

Create a new ansible .yml file and put this in:

- name: install python packages
  pip: name={{item.name}} version={{item.version}}
  with_items:
    - { name: 'Jinja2', version: '2.7.1' }  # The "version .." string will be colored wrong.
    - { name: 'MySQL-python', version: '1.2.5' }  # Same here.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/4075943-yaml-flow-mappings-are-not-highlighted-correctly?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Vim 7.3 Currently Unsupported

Vim 7.3 is currently unsupported since the included YAML syntax causes Vim to hang due to the old RegExp engine.

The most easily implemented solution would be to only match in 7.4 what hangs in 7.3. This may cause syntax coloring to be sparse, but it would prevent the hangs.

The second easy implementation is to fall back to the distribution included YAML syntax file in 7.3 and earlier.

Use 2 spaces instead of 4

Would it be possible to configure the plugin to use 2 spaces instead of 4? It looks like everyone is using 2 spaces by the way.

one-word "key: value" has wrong color

- name: ls some dir
  tags: list
  shell: echo `ls /bin`

The word "list" in the "tags:" line will have a key color, and not a value color (i.e. like "ls some dir").

Update Docs Please

Hi,

Somewhere in the README it should say that a user needs to add something like this to their .vimrc file

au BufNewFile,BufRead *.yml set syntax=ansible

Indenting line when typing a dash in the middle of that line

Hello,
I ran into trouble a few times when indent was automatically increased for a line when I edited it and put a dash somewhere in the middle of the line.

I changed the line
setlocal indentkeys=!^Fo,O,0#,<:>,-
to
setlocal indentkeys=!^Fo,O,0#,<:>,=-
in indent/ansible.vim for now, but I don't know Vim enough to know whether this is a solution or disabled something else.

Wanted to let you know. Cheers!

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/8961819-indenting-line-when-typing-a-dash-in-the-middle-of-that-line?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Add Jinja highlighting for special Ansible functions

Strings, encased or otherwise, should be highlighted as if they were between Jinja variable blocks for the following keys:

  • when
  • changed_when
  • with_*

There are probably more, but they can be added later.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1446702-add-jinja-highlighting-for-special-ansible-functions?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

New pattern for yamlMapping breaks ansibleString

Commit 8050b3f breaks this silly example:

- name: silly rule
  command: echo "when {{ when }}"
  when: some_condition

The problem is that the first } now ends the yamlMapping group, and so the second " starts an ansibleString group, which continues onto the last line. Here is a screenshot:
broken_string

Add me as a maintainer.

I am interested in maintaining this project. I have recently started using Ansible, and I need good integration with vim.

See the pull request I just submitted for some suggested tweaks.

If you add me as a maintainer, then I will see what I can do about open issues. I am also interested in

  • changing the way that indentation works
  • adding support for SnipMate/UltiSnip
  • adding support for Syntastic

I maintain matchit, which has been part of the standard vim distribution since vim 6.0. I have several other scripts on vim.org. More recently, I have been working on customizing vim for Drupal. (Although that is a project on drupal.org, it is mostly a collection of vim scripts.)

Lines with two colons in them have improper double highlighting

When working with a Yum repo:

    name:  http://example.com/url

the http: is highlighted just like name:. The expected behavior is that it is highlighted like any other field.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/24702940-lines-with-two-colons-in-them-have-improper-double-highlighting?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Re-implement Scalar Blocks ?

Scalar blocks were removed in c6aca1c due to #6.

Scalar blocks and explicit tags are quite nearly the most complicated aspect of the YAML 1.2 specification and add very little value by being highlighted.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/2865271-re-implement-scalar-blocks?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Commenting a vertical block of code doesn't work

I have an issue when commenting a vertical block of code. It would break the identation and then not propagate the changes over the whole block.
For exemple his code:

  1 ---
  2   - name: test
  3     command: true
  4     register: myrun
  5 
  6   - find: 
  7       paths: /path
  8       patterns: "*"
  9       file_type: file
 10       recurse: yes
 11     register: dir_files

if i select Ctrl-V lines 6-11 and do I then enter the # sign, and ESC, it becomes:

  1 ---
  2   - name: test
  3     command: true
  4     register: myrun
  5 
  6 #- find: 
  7       paths: /path
  8       patterns: "*"
  9       file_type: file
 10       recurse: yes
 11     register: dir_files

Any idea how to fix this to be able to comment code? Thanks.
Any idea how to debug this?

Wrong syntax highlight in neovim

VIM 7.4.488:
screen shot 2015-04-25 at 21 38 29

NVIM 0.0.0-alpha+201504231827:
screen shot 2015-04-25 at 21 37 46

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/12097563-wrong-syntax-highlight-in-neovim?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

Add Maintainer

Add me as a maintainer? I can at least fix most of the syntax issues people are having. :)

Fix YAML Highlighting

Numbers and sequence markers (-) are being highlighted in the middle of strings.

This tends to be a bit distracting:
screen shot 2013-12-12 at 12 49 56 am

Vim hangs on OSX

Anybody had this trouble? I just have half file opened, other half is not displayed. And Vim is not functioning. Used bundle to install this package. After pushing ctrl+c rest of file appears, vim still stays unfunctional.

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.