1 " LLVM coding guidelines conformance for VIM
4 " Maintainer: The LLVM Team, http://llvm.org
5 " WARNING: Read before you source in all these commands and macros! Some
6 " of them may change VIM behavior that you depend on.
8 " You can run VIM with these settings without changing your current setup with:
9 " $ vim -u /path/to/llvm/utils/vim/vimrc
14 " A tab produces a 2-space indentation
19 " Highlight trailing whitespace and lines longer than 80 columns.
20 highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
21 highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
23 " Lines longer than 80 columns.
24 au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1)
26 " Whitespace at the end of a line. This little dance suppresses
27 " whitespace that has just been typed.
28 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)
34 au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
35 au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
36 au InsertLeave * syntax match WhitespaceEOL /\s\+$/
39 " Enable filetype detection
43 " C/C++ programming helpers
46 autocmd FileType * set nocindent smartindent
47 autocmd FileType c,cpp set cindent
49 " 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.
52 set cinoptions=:0,g0,(0,Ws,l1
53 " Add and delete spaces in increments of `shiftwidth' for tabs
56 " Highlight syntax in programming languages
59 " LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
60 " so it's important to categorize them as such.
62 au! BufRead,BufNewFile *Makefile* set filetype=make
65 " In Makefiles, don't expand tabs to spaces, since we need the actual tabs
66 autocmd FileType make set noexpandtab
68 " Useful macros for cleaning up code to conform to LLVM coding guidelines
70 " Delete trailing whitespace and tabs at the end of each line
71 command! DeleteTrailingWs :%s/\s\+$//
73 " Convert all tab characters to two spaces
74 command! Untab :%s/\t/ /g
76 " Enable syntax highlighting for LLVM files. To use, copy
77 " utils/vim/llvm.vim to ~/.vim/syntax .
79 au! BufRead,BufNewFile *.ll set filetype=llvm
82 " Enable syntax highlighting for tablegen files. To use, copy
83 " utils/vim/tablegen.vim to ~/.vim/syntax .
85 au! BufRead,BufNewFile *.td set filetype=tablegen
88 " Additional vim features to optionally uncomment.
95 " Clang code-completion support. This is highly experimental!
97 " TODO: code-completing on
99 " turns up some peculiarities -- "asm("?
101 " A path to a clang executable.
102 let g:clang_path = "clang++"
104 " A list of options to add to the clang commandline, for example to add
105 " include paths, predefined macros, and language options.
108 \ "-D__STDC_LIMIT_MACROS=1","-D__STDC_CONSTANT_MACROS=1",
111 function! ClangComplete(findstart, base)
113 " In findstart mode, look for the beginning of the current identifier.
114 let l:line = getline('.')
115 let l:start = col('.') - 1
116 while l:start > 0 && l:line[l:start - 1] =~ '\i'
122 " Get the current line and column numbers.
126 " Build a clang commandline to do code completion on stdin.
127 let l:the_command = shellescape(g:clang_path) .
128 \ " -cc1 -code-completion-at=-:" . l:l . ":" . l:c
129 for l:opt in g:clang_opts
130 let l:the_command .= " " . shellescape(l:opt)
133 " Copy the contents of the current buffer into a string for stdin.
134 " TODO: The extra space at the end is for working around clang's
135 " apparent inability to do code completion at the very end of the
137 " TODO: Is it better to feed clang the entire file instead of truncating
138 " it at the current line?
139 let l:process_input = join(getline(1, l:l), "\n") . " "
142 let l:input_lines = split(system(l:the_command, l:process_input), "\n")
145 for l:input_line in l:input_lines
146 " Vim's substring operator is annoyingly inconsistent with python's.
147 if l:input_line[:11] == 'COMPLETION: '
148 let l:value = l:input_line[12:]
150 " Chop off anything after " : ", if present, and move it to the menu.
152 let l:spacecolonspace = stridx(l:value, " : ")
153 if l:spacecolonspace != -1
154 let l:menu = l:value[l:spacecolonspace+3:]
155 let l:value = l:value[:l:spacecolonspace-1]
158 " Chop off " (Hidden)", if present, and move it to the menu.
159 let l:hidden = stridx(l:value, " (Hidden)")
161 let l:menu .= " (Hidden)"
162 let l:value = l:value[:l:hidden-1]
165 " Handle "Pattern". TODO: Make clang less weird.
166 if l:value == "Pattern"
168 let l:pound = stridx(l:value, "#")
169 " Truncate the at the first [#, <#, or {#.
171 let l:value = l:value[:l:pound-2]
175 " Filter out results which don't match the base string.
177 if l:value[:strlen(a:base)-1] != a:base
182 " TODO: Don't dump the raw input into info, though it's nice for now.
183 " TODO: The kind string?
187 \ "info": l:input_line,
191 if complete_add(l:item) == 0
198 elseif l:input_line[:9] == "OVERLOAD: "
199 " An overload candidate. Use a crazy hack to get vim to
200 " display the results. TODO: Make this better.
201 let l:value = l:input_line[10:]
205 \ "info": l:input_line,
209 if complete_add(l:item) == 0
221 endfunction ClangComplete
223 " Uncomment this to enable the highly-broken autocompletion support.
224 "set omnifunc=ClangComplete