blob: 7b1fd872b274c9cae5916ece46e5b18997dc873f [file] [log] [blame]
Misha Brukman3d6eea52005-04-24 17:05:04 +00001" LLVM coding guidelines conformance for VIM
Misha Brukmanadf4e4d2009-01-02 16:26:14 +00002"
3" Maintainer: The LLVM Team, http://llvm.org
Misha Brukman3d6eea52005-04-24 17:05:04 +00004" WARNING: Read before you source in all these commands and macros! Some
Misha Brukman2bb55082005-05-12 21:41:48 +00005" of them may change VIM behavior that you depend on.
Misha Brukmanadf4e4d2009-01-02 16:26:14 +00006"
7" You can run VIM with these settings without changing your current setup with:
8" $ vim -u /path/to/llvm/utils/vim/vimrc
9
10" It's VIM, not VI
11set nocompatible
Misha Brukman3d6eea52005-04-24 17:05:04 +000012
13" Wrap text at 80 cols
14set textwidth=80
15
16" A tab produces a 2-space indentation
Dan Gohmanf225d2e2009-01-04 00:05:43 +000017set softtabstop=2
Misha Brukman3d6eea52005-04-24 17:05:04 +000018set shiftwidth=2
19set expandtab
20
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000021" Highlight trailing whitespace
22highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
23match WhitespaceEOL /\s\+$/
24
Dan Gohman5e59c272009-01-21 21:30:25 +000025" Enable filetype detection
26filetype on
27
Misha Brukman2bb55082005-05-12 21:41:48 +000028" Optional
29" C/C++ programming helpers
Dan Gohman5e59c272009-01-21 21:30:25 +000030augroup csrc
31 au!
32 autocmd FileType * set nocindent smartindent
33 autocmd FileType c,cpp set cindent
34augroup END
Dan Gohmana0741ba2009-01-04 18:59:55 +000035" Set a few indentation parameters. See the VIM help for cinoptions-values for
36" details. These aren't absolute rules; they're just an approximation of
37" common style in LLVM source.
38set cinoptions=:0,g0,(0,Ws
Misha Brukman2bb55082005-05-12 21:41:48 +000039" Add and delete spaces in increments of `shiftwidth' for tabs
40set smarttab
41
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000042" Highlight syntax in programming languages
43syntax on
44
Misha Brukman3d6eea52005-04-24 17:05:04 +000045" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
46" so it's important to categorize them as such.
47augroup filetype
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000048 au! BufRead,BufNewFile *Makefile* set filetype=make
Misha Brukman3d6eea52005-04-24 17:05:04 +000049augroup END
50
51" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
52autocmd FileType make set noexpandtab
53
54" Useful macros for cleaning up code to conform to LLVM coding guidelines
55
56" Delete trailing whitespace and tabs at the end of each line
Misha Brukman5539a1e2009-01-08 02:17:30 +000057command! DeleteTrailingWs :%s/\s\+$//
Misha Brukman3d6eea52005-04-24 17:05:04 +000058
59" Convert all tab characters to two spaces
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000060command! Untab :%s/\t/ /g
Dan Gohman789da272009-01-21 21:47:51 +000061
62" Enable syntax highlighting for LLVM files. To use, copy
63" utils/vim/llvm.vim to ~/.vim/syntax .
64augroup filetype
65 au! BufRead,BufNewFile *.ll set filetype=llvm
66augroup END
67
68" Enable syntax highlighting for tablegen files. To use, copy
69" utils/vim/tablegen.vim to ~/.vim/syntax .
70augroup filetype
71 au! BufRead,BufNewFile *.td set filetype=tablegen
72augroup END