xref: /llvm-project-15.0.7/llvm/utils/vim/vimrc (revision 455be5a0)
1" LLVM coding guidelines conformance for VIM
2"
3" Maintainer: The LLVM Team, http://llvm.org
4" WARNING:    Read before you source in all these commands and macros!  Some
5"             of them may change VIM behavior that you depend on.
6"
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
12
13" Wrap text at 80 cols
14set textwidth=80
15
16" A tab produces a 2-space indentation
17set softtabstop=2
18set shiftwidth=2
19set expandtab
20
21" Highlight trailing whitespace
22highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
23match WhitespaceEOL /\s\+$/
24
25" Enable filetype detection
26filetype on
27
28" Optional
29" C/C++ programming helpers
30augroup csrc
31  au!
32  autocmd FileType *      set nocindent smartindent
33  autocmd FileType c,cpp  set cindent
34augroup END
35" 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
39" Add and delete spaces in increments of `shiftwidth' for tabs
40set smarttab
41
42" Highlight syntax in programming languages
43syntax on
44
45" 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
48  au! BufRead,BufNewFile *Makefile* set filetype=make
49augroup 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
57command! DeleteTrailingWs :%s/\s\+$//
58
59" Convert all tab characters to two spaces
60command! Untab :%s/\t/  /g
61