Add Revision keywords to these files, as it's common for them to be
[oota-llvm.git] / utils / vim / vimrc
1 " LLVM coding guidelines conformance for VIM
2 " $Revision$
3 "
4 " Maintainer: The LLVM Team, http://llvm.org
5 " WARNING:    Read before you source in all these commands and macros!  Some
6 "             of them may change VIM behavior that you depend on.
7 "
8 " You can run VIM with these settings without changing your current setup with:
9 " $ vim -u /path/to/llvm/utils/vim/vimrc
10
11 " It's VIM, not VI
12 set nocompatible
13
14 " A tab produces a 2-space indentation
15 set softtabstop=2
16 set shiftwidth=2
17 set expandtab
18
19 " Highlight trailing whitespace and lines longer than 80 columns.
20 highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
21 highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
22 if v:version >= 702
23   " Lines longer than 80 columns.
24   au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1)
25
26   " Whitespace at the end of a line. This little dance suppresses
27   " of whitespace that has just been typed.
28   au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
29   au InsertEnter * call matchdelete(w:m1)
30   au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1)
31   au InsertLeave * call matchdelete(w:m2)
32   au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
33 else
34   au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
35   au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
36   au InsertLeave * syntax match WhitespaceEOL /\s\+$/
37 endif
38
39 " Enable filetype detection
40 filetype on
41
42 " Optional
43 " C/C++ programming helpers
44 augroup csrc
45   au!
46   autocmd FileType *      set nocindent smartindent
47   autocmd FileType c,cpp  set cindent
48 augroup END
49 " Set a few indentation parameters. See the VIM help for cinoptions-values for
50 " details.  These aren't absolute rules; they're just an approximation of
51 " common style in LLVM source.
52 set cinoptions=:0,g0,(0,Ws,l1
53 " Add and delete spaces in increments of `shiftwidth' for tabs
54 set smarttab
55
56 " Highlight syntax in programming languages
57 syntax on
58
59 " LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
60 " so it's important to categorize them as such.
61 augroup filetype
62   au! BufRead,BufNewFile *Makefile* set filetype=make
63 augroup END
64
65 " In Makefiles, don't expand tabs to spaces, since we need the actual tabs
66 autocmd FileType make set noexpandtab
67
68 " Useful macros for cleaning up code to conform to LLVM coding guidelines
69
70 " Delete trailing whitespace and tabs at the end of each line
71 command! DeleteTrailingWs :%s/\s\+$//
72
73 " Convert all tab characters to two spaces
74 command! Untab :%s/\t/  /g
75
76 " Enable syntax highlighting for LLVM files. To use, copy
77 " utils/vim/llvm.vim to ~/.vim/syntax .
78 augroup filetype
79   au! BufRead,BufNewFile *.ll     set filetype=llvm
80 augroup END
81
82 " Enable syntax highlighting for tablegen files. To use, copy
83 " utils/vim/tablegen.vim to ~/.vim/syntax .
84 augroup filetype
85   au! BufRead,BufNewFile *.td     set filetype=tablegen
86 augroup END
87
88 " Additional vim features to optionally uncomment.
89 "set showcmd
90 "set showmatch
91 "set showmode
92 "set incsearch
93 "set ruler