Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
Forked from iangreenleaf/yaml.vim
Created October 25, 2015 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqueswww/1c90ad7235ddb864e796 to your computer and use it in GitHub Desktop.
Save jacqueswww/1c90ad7235ddb864e796 to your computer and use it in GitHub Desktop.
Dumb-smart indentation for Yaml
" Vim indent file
" Language: Yaml
" Author: Ian Young
" Get it bundled for pathogen: https://github.com/avakhov/vim-yaml
if exists("b:did_indent")
finish
endif
"runtime! indent/ruby.vim
"unlet! b:did_indent
let b:did_indent = 1
setlocal autoindent sw=2 et
setlocal indentexpr=GetYamlIndent()
setlocal indentkeys=o,O,*<Return>,!^F
function! GetYamlIndent()
let lnum = v:lnum - 1
if lnum == 0
return 0
endif
let line = substitute(getline(lnum),'\s\+$','','')
let indent = indent(lnum)
let increase = indent + &sw
if line =~ ':$'
return increase
else
return indent
endif
endfunction
" vim:set sw=2:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment