File: tab-indent.vim

package info (click to toggle)
vimacs 0.95-1.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 148 kB
  • ctags: 257
  • sloc: sh: 37; makefile: 29
file content (68 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
"" TabIndent (1.0)
"
" Overloads <Tab> to either insert a tab, or perform indentation
"

"
" Copyright (C) 2002  Andre Pang <ozone@vimacs.cx>
"
" Please see the documentation (tab-indent.txt) for installation and usage
" notes.
"

if exists("loaded_TabIndent")
  finish
endif

if !exists("g:TabIndentStyle")
  let g:TabIndentStyle = 1
endif

inoremap <silent> <Tab> <C-r>=<SID>TabOrIndent()<CR>

function! <SID>TabOrIndent()

  let saved_cpoptions = &cpoptions
  set cpoptions-=<,C,k
  set cpoptions+=B

  let indent_blank_line = "\<End>x\<C-o>==\<End>\<Left>\<Del>"
  let indent = "\<C-o>=="
  let real_tab = "\<Tab>"

  let &cpoptions = saved_cpoptions

  if &cindent || &indentexpr != ""

    if g:TabIndentStyle == 1 || g:TabIndentStyle == "emacs" || g:TabIndentStyle == "always"
      if getline('.') =~ '^\s*$'
	return indent_blank_line
      else
	return indent
      endif

    elseif g:TabIndentStyle == 2 || g:TabIndentStyle == "whitespace"
      if virtcol('.') <= indent(line('.'))
	return indent 
      else
	return real_tab
      endif

    elseif g:TabIndentStyle == 3 || g:TabIndentStyle == "startofline"
      if virtcol('.') <= indent(line('.')) || virtcol('.') == 1
	return indent 
      else
	return real_tab
      endif
      
    endif

  else
    return real_tab
  endif

endfunction

let loaded_TabIndent = 1