Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 1 | " LLVM coding guidelines conformance for VIM |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 2 | " |
| 3 | " Maintainer: The LLVM Team, http://llvm.org |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 4 | " WARNING: Read before you source in all these commands and macros! Some |
Misha Brukman | 2bb5508 | 2005-05-12 21:41:48 +0000 | [diff] [blame] | 5 | " of them may change VIM behavior that you depend on. |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 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 |
| 11 | set nocompatible |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 12 | |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 13 | " A tab produces a 2-space indentation |
Dan Gohman | f225d2e | 2009-01-04 00:05:43 +0000 | [diff] [blame] | 14 | set softtabstop=2 |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 15 | set shiftwidth=2 |
| 16 | set expandtab |
| 17 | |
Dan Gohman | d30103d | 2010-02-26 21:24:46 +0000 | [diff] [blame^] | 18 | " Highlight trailing whitespace and lines longer than 80 columns. |
| 19 | highlight LongLine ctermbg=DarkYellow guibg=DarkYellow |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 20 | highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow |
Dan Gohman | d30103d | 2010-02-26 21:24:46 +0000 | [diff] [blame^] | 21 | if 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) |
| 32 | else |
| 33 | au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/ |
| 34 | au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/ |
| 35 | au InsertLeave * syntax match WhitespaceEOL /\s\+$/ |
| 36 | endif |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 37 | |
Dan Gohman | 5e59c27 | 2009-01-21 21:30:25 +0000 | [diff] [blame] | 38 | " Enable filetype detection |
| 39 | filetype on |
| 40 | |
Misha Brukman | 2bb5508 | 2005-05-12 21:41:48 +0000 | [diff] [blame] | 41 | " Optional |
| 42 | " C/C++ programming helpers |
Dan Gohman | 5e59c27 | 2009-01-21 21:30:25 +0000 | [diff] [blame] | 43 | augroup csrc |
| 44 | au! |
| 45 | autocmd FileType * set nocindent smartindent |
| 46 | autocmd FileType c,cpp set cindent |
| 47 | augroup END |
Dan Gohman | a0741ba | 2009-01-04 18:59:55 +0000 | [diff] [blame] | 48 | " 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 Gohman | acb75a9 | 2010-01-09 17:15:21 +0000 | [diff] [blame] | 51 | set cinoptions=:0,g0,(0,Ws,l1 |
Misha Brukman | 2bb5508 | 2005-05-12 21:41:48 +0000 | [diff] [blame] | 52 | " Add and delete spaces in increments of `shiftwidth' for tabs |
| 53 | set smarttab |
| 54 | |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 55 | " Highlight syntax in programming languages |
| 56 | syntax on |
| 57 | |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 58 | " LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile, |
| 59 | " so it's important to categorize them as such. |
| 60 | augroup filetype |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 61 | au! BufRead,BufNewFile *Makefile* set filetype=make |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 62 | augroup END |
| 63 | |
| 64 | " In Makefiles, don't expand tabs to spaces, since we need the actual tabs |
| 65 | autocmd 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 Brukman | 5539a1e | 2009-01-08 02:17:30 +0000 | [diff] [blame] | 70 | command! DeleteTrailingWs :%s/\s\+$// |
Misha Brukman | 3d6eea5 | 2005-04-24 17:05:04 +0000 | [diff] [blame] | 71 | |
| 72 | " Convert all tab characters to two spaces |
Misha Brukman | adf4e4d | 2009-01-02 16:26:14 +0000 | [diff] [blame] | 73 | command! Untab :%s/\t/ /g |
Dan Gohman | 789da27 | 2009-01-21 21:47:51 +0000 | [diff] [blame] | 74 | |
| 75 | " Enable syntax highlighting for LLVM files. To use, copy |
| 76 | " utils/vim/llvm.vim to ~/.vim/syntax . |
| 77 | augroup filetype |
| 78 | au! BufRead,BufNewFile *.ll set filetype=llvm |
| 79 | augroup END |
| 80 | |
| 81 | " Enable syntax highlighting for tablegen files. To use, copy |
| 82 | " utils/vim/tablegen.vim to ~/.vim/syntax . |
| 83 | augroup filetype |
| 84 | au! BufRead,BufNewFile *.td set filetype=tablegen |
| 85 | augroup END |
Dan Gohman | d30103d | 2010-02-26 21:24:46 +0000 | [diff] [blame^] | 86 | |
| 87 | " Additional vim features to optionally uncomment. |
| 88 | "set showcmd |
| 89 | "set showmatch |
| 90 | "set showmode |
| 91 | "set incsearch |
| 92 | "set ruler |