blob: 8ae3e678cfeaf05badf011b3b346de45f904400a [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001" LLVM coding guidelines conformance for VIM
Dan Gohmanff418a22010-02-26 21:38:04 +00002" $Revision$
Misha Brukmanb701a472009-01-02 16:26:14 +00003"
4" Maintainer: The LLVM Team, http://llvm.org
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005" WARNING: Read before you source in all these commands and macros! Some
6" of them may change VIM behavior that you depend on.
Misha Brukmanb701a472009-01-02 16:26:14 +00007"
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
12set nocompatible
Dan Gohmanf17a25c2007-07-18 16:29:46 +000013
Dan Gohmanf17a25c2007-07-18 16:29:46 +000014" A tab produces a 2-space indentation
Dan Gohmancdf33642009-01-04 00:05:43 +000015set softtabstop=2
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016set shiftwidth=2
17set expandtab
18
Dan Gohmanc04904b2010-02-26 21:24:46 +000019" Highlight trailing whitespace and lines longer than 80 columns.
20highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
Misha Brukmanb701a472009-01-02 16:26:14 +000021highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
Dan Gohmanc04904b2010-02-26 21:24:46 +000022if 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
Dan Gohmanbdf047c2010-02-26 21:45:37 +000027 " whitespace that has just been typed.
Dan Gohmanc04904b2010-02-26 21:24:46 +000028 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)
33else
34 au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
35 au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
36 au InsertLeave * syntax match WhitespaceEOL /\s\+$/
37endif
Misha Brukmanb701a472009-01-02 16:26:14 +000038
Dan Gohmanbe8c7192009-01-21 21:30:25 +000039" Enable filetype detection
40filetype on
41
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042" Optional
43" C/C++ programming helpers
Dan Gohmanbe8c7192009-01-21 21:30:25 +000044augroup csrc
45 au!
46 autocmd FileType * set nocindent smartindent
47 autocmd FileType c,cpp set cindent
48augroup END
Dan Gohman07aba402009-01-04 18:59:55 +000049" 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.
Dan Gohman40647222010-01-09 17:15:21 +000052set cinoptions=:0,g0,(0,Ws,l1
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053" Add and delete spaces in increments of `shiftwidth' for tabs
54set smarttab
55
Misha Brukmanb701a472009-01-02 16:26:14 +000056" Highlight syntax in programming languages
57syntax on
58
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
60" so it's important to categorize them as such.
61augroup filetype
Misha Brukmanb701a472009-01-02 16:26:14 +000062 au! BufRead,BufNewFile *Makefile* set filetype=make
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063augroup END
64
65" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
66autocmd 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
Misha Brukman417b3112009-01-08 02:17:30 +000071command! DeleteTrailingWs :%s/\s\+$//
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072
73" Convert all tab characters to two spaces
Misha Brukmanb701a472009-01-02 16:26:14 +000074command! Untab :%s/\t/ /g
Dan Gohman8e66ba42009-01-21 21:47:51 +000075
76" Enable syntax highlighting for LLVM files. To use, copy
77" utils/vim/llvm.vim to ~/.vim/syntax .
78augroup filetype
79 au! BufRead,BufNewFile *.ll set filetype=llvm
80augroup END
81
82" Enable syntax highlighting for tablegen files. To use, copy
83" utils/vim/tablegen.vim to ~/.vim/syntax .
84augroup filetype
85 au! BufRead,BufNewFile *.td set filetype=tablegen
86augroup END
Dan Gohmanc04904b2010-02-26 21:24:46 +000087
88" Additional vim features to optionally uncomment.
89"set showcmd
90"set showmatch
91"set showmode
92"set incsearch
93"set ruler