summaryrefslogtreecommitdiffstats
path: root/runtime/indent/vim.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-06-13 20:20:40 +0000
committerBram Moolenaar <Bram@vim.org>2004-06-13 20:20:40 +0000
commit071d4279d6ab81b7187b48f3a0fc61e587b6db6c (patch)
tree221cbe3c40e043163c06f61c52a7ba2eb41e12ce /runtime/indent/vim.vim
parentb4210b3bc14e2918f153a7307530fbe6eba659e1 (diff)
updated for version 7.0001v7.0001
Diffstat (limited to 'runtime/indent/vim.vim')
-rw-r--r--runtime/indent/vim.vim65
1 files changed, 65 insertions, 0 deletions
diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim
new file mode 100644
index 0000000000..0de77748c0
--- /dev/null
+++ b/runtime/indent/vim.vim
@@ -0,0 +1,65 @@
+" Vim indent file
+" Language: Vim script
+" Maintainer: Bram Moolenaar <Bram@vim.org>
+" Last Change: 2003 May 25
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetVimIndent()
+setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\
+
+" Only define the function once.
+if exists("*GetVimIndent")
+ finish
+endif
+
+function GetVimIndent()
+ " Find a non-blank line above the current line.
+ let lnum = prevnonblank(v:lnum - 1)
+
+ " If the current line doesn't start with '\' and below a line that starts
+ " with '\', use the indent of the line above it.
+ if getline(v:lnum) !~ '^\s*\\'
+ while lnum > 0 && getline(lnum) =~ '^\s*\\'
+ let lnum = lnum - 1
+ endwhile
+ endif
+
+ " At the start of the file use zero indent.
+ if lnum == 0
+ return 0
+ endif
+
+ " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
+ " and :else. Add it three times for a line that starts with '\' after
+ " a line that doesn't.
+ let ind = indent(lnum)
+ if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\'
+ let ind = ind + &sw * 3
+ elseif getline(lnum) =~ '\(^\||\)\s*\(if\|wh\%[ile]\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>'
+ let ind = ind + &sw
+ elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
+ let ind = ind + &sw
+ endif
+
+ " If the previous line contains an "end" after a pipe, but not in an ":au"
+ " command.
+ if getline(lnum) =~ '|\s*\(ene\@!\)' && getline(lnum) !~ '^\s*au\%[tocmd]'
+ let ind = ind - &sw
+ endif
+
+
+ " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry,
+ " :endfun, :else and :augroup END.
+ if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)'
+ let ind = ind - &sw
+ endif
+
+ return ind
+endfunction
+
+" vim:sw=2