blob: 1385407adcc13132ee8324239eb48203e1e10b28 [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
Misha Brukman3d6eea52005-04-24 17:05:04 +000013" A tab produces a 2-space indentation
Dan Gohmanf225d2e2009-01-04 00:05:43 +000014set softtabstop=2
Misha Brukman3d6eea52005-04-24 17:05:04 +000015set shiftwidth=2
16set expandtab
17
Dan Gohmand30103d2010-02-26 21:24:46 +000018" Highlight trailing whitespace and lines longer than 80 columns.
19highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000020highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
Dan Gohmand30103d2010-02-26 21:24:46 +000021if v:version >= 702
22 " Lines longer than 80 columns.
23 au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1)
24
25 " Whitespace at the end of a line. This little dance suppresses
26 " of whitespace that has just been typed.
27 au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
28 au InsertEnter * call matchdelete(w:m1)
29 au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1)
30 au InsertLeave * call matchdelete(w:m2)
31 au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
32else
33 au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
34 au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
35 au InsertLeave * syntax match WhitespaceEOL /\s\+$/
36endif
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000037
Dan Gohman5e59c272009-01-21 21:30:25 +000038" Enable filetype detection
39filetype on
40
Misha Brukman2bb55082005-05-12 21:41:48 +000041" Optional
42" C/C++ programming helpers
Dan Gohman5e59c272009-01-21 21:30:25 +000043augroup csrc
44 au!
45 autocmd FileType * set nocindent smartindent
46 autocmd FileType c,cpp set cindent
47augroup END
Dan Gohmana0741ba2009-01-04 18:59:55 +000048" Set a few indentation parameters. See the VIM help for cinoptions-values for
49" details. These aren't absolute rules; they're just an approximation of
50" common style in LLVM source.
Dan Gohmanacb75a92010-01-09 17:15:21 +000051set cinoptions=:0,g0,(0,Ws,l1
Misha Brukman2bb55082005-05-12 21:41:48 +000052" Add and delete spaces in increments of `shiftwidth' for tabs
53set smarttab
54
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000055" Highlight syntax in programming languages
56syntax on
57
Misha Brukman3d6eea52005-04-24 17:05:04 +000058" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
59" so it's important to categorize them as such.
60augroup filetype
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000061 au! BufRead,BufNewFile *Makefile* set filetype=make
Misha Brukman3d6eea52005-04-24 17:05:04 +000062augroup END
63
64" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
65autocmd FileType make set noexpandtab
66
67" Useful macros for cleaning up code to conform to LLVM coding guidelines
68
69" Delete trailing whitespace and tabs at the end of each line
Misha Brukman5539a1e2009-01-08 02:17:30 +000070command! DeleteTrailingWs :%s/\s\+$//
Misha Brukman3d6eea52005-04-24 17:05:04 +000071
72" Convert all tab characters to two spaces
Misha Brukmanadf4e4d2009-01-02 16:26:14 +000073command! Untab :%s/\t/ /g
Dan Gohman789da272009-01-21 21:47:51 +000074
75" Enable syntax highlighting for LLVM files. To use, copy
76" utils/vim/llvm.vim to ~/.vim/syntax .
77augroup filetype
78 au! BufRead,BufNewFile *.ll set filetype=llvm
79augroup END
80
81" Enable syntax highlighting for tablegen files. To use, copy
82" utils/vim/tablegen.vim to ~/.vim/syntax .
83augroup filetype
84 au! BufRead,BufNewFile *.td set filetype=tablegen
85augroup END
Dan Gohmand30103d2010-02-26 21:24:46 +000086
87" Additional vim features to optionally uncomment.
88"set showcmd
89"set showmatch
90"set showmode
91"set incsearch
92"set ruler