vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. " LLVM coding guidelines conformance for VIM
  2. " $Revision$
  3. "
  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.
  7. "
  8. " You can run VIM with these settings without changing your current setup with:
  9. " $ vim -u /path/to/llvm/utils/vim/vimrc
  10. " It's VIM, not VI
  11. set nocompatible
  12. " A tab produces a 2-space indentation
  13. set softtabstop=2
  14. set shiftwidth=2
  15. set expandtab
  16. " Highlight trailing whitespace and lines longer than 80 columns.
  17. highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
  18. highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
  19. if v:version >= 702
  20. " Lines longer than 80 columns.
  21. au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1)
  22. " Whitespace at the end of a line. This little dance suppresses
  23. " whitespace that has just been typed.
  24. au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
  25. au InsertEnter * call matchdelete(w:m1)
  26. au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1)
  27. au InsertLeave * call matchdelete(w:m2)
  28. au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
  29. else
  30. au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
  31. au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
  32. au InsertLeave * syntax match WhitespaceEOL /\s\+$/
  33. endif
  34. " Enable filetype detection
  35. filetype on
  36. " Optional
  37. " C/C++ programming helpers
  38. augroup csrc
  39. au!
  40. autocmd FileType * set nocindent smartindent
  41. autocmd FileType c,cpp set cindent
  42. augroup END
  43. " Set a few indentation parameters. See the VIM help for cinoptions-values for
  44. " details. These aren't absolute rules; they're just an approximation of
  45. " common style in LLVM source.
  46. set cinoptions=:0,g0,(0,Ws,l1
  47. " Add and delete spaces in increments of `shiftwidth' for tabs
  48. set smarttab
  49. " Highlight syntax in programming languages
  50. syntax on
  51. " LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
  52. " so it's important to categorize them as such.
  53. augroup filetype
  54. au! BufRead,BufNewFile *Makefile* set filetype=make
  55. augroup END
  56. " In Makefiles, don't expand tabs to spaces, since we need the actual tabs
  57. autocmd FileType make set noexpandtab
  58. " Useful macros for cleaning up code to conform to LLVM coding guidelines
  59. " Delete trailing whitespace and tabs at the end of each line
  60. command! DeleteTrailingWs :%s/\s\+$//
  61. " Convert all tab characters to two spaces
  62. command! Untab :%s/\t/ /g
  63. " Enable syntax highlighting for LLVM files. To use, copy
  64. " utils/vim/syntax/llvm.vim to ~/.vim/syntax .
  65. augroup filetype
  66. au! BufRead,BufNewFile *.ll set filetype=llvm
  67. augroup END
  68. " Enable syntax highlighting for tablegen files. To use, copy
  69. " utils/vim/syntax/tablegen.vim to ~/.vim/syntax .
  70. augroup filetype
  71. au! BufRead,BufNewFile *.td set filetype=tablegen
  72. augroup END
  73. " Enable syntax highlighting for reStructuredText files. To use, copy
  74. " rest.vim (http://www.vim.org/scripts/script.php?script_id=973)
  75. " to ~/.vim/syntax .
  76. augroup filetype
  77. au! BufRead,BufNewFile *.rst set filetype=rest
  78. augroup END
  79. " Additional vim features to optionally uncomment.
  80. "set showcmd
  81. "set showmatch
  82. "set showmode
  83. "set incsearch
  84. "set ruler
  85. " Clang code-completion support. This is somewhat experimental!
  86. " A path to a clang executable.
  87. let g:clang_path = "clang++"
  88. " A list of options to add to the clang commandline, for example to add
  89. " include paths, predefined macros, and language options.
  90. let g:clang_opts = [
  91. \ "-x","c++",
  92. \ "-D__STDC_LIMIT_MACROS=1","-D__STDC_CONSTANT_MACROS=1",
  93. \ "-Iinclude" ]
  94. function! ClangComplete(findstart, base)
  95. if a:findstart == 1
  96. " In findstart mode, look for the beginning of the current identifier.
  97. let l:line = getline('.')
  98. let l:start = col('.') - 1
  99. while l:start > 0 && l:line[l:start - 1] =~ '\i'
  100. let l:start -= 1
  101. endwhile
  102. return l:start
  103. endif
  104. " Get the current line and column numbers.
  105. let l:l = line('.')
  106. let l:c = col('.')
  107. " Build a clang commandline to do code completion on stdin.
  108. let l:the_command = shellescape(g:clang_path) .
  109. \ " -cc1 -code-completion-at=-:" . l:l . ":" . l:c
  110. for l:opt in g:clang_opts
  111. let l:the_command .= " " . shellescape(l:opt)
  112. endfor
  113. " Copy the contents of the current buffer into a string for stdin.
  114. " TODO: The extra space at the end is for working around clang's
  115. " apparent inability to do code completion at the very end of the
  116. " input.
  117. " TODO: Is it better to feed clang the entire file instead of truncating
  118. " it at the current line?
  119. let l:process_input = join(getline(1, l:l), "\n") . " "
  120. " Run it!
  121. let l:input_lines = split(system(l:the_command, l:process_input), "\n")
  122. " Parse the output.
  123. for l:input_line in l:input_lines
  124. " Vim's substring operator is annoyingly inconsistent with python's.
  125. if l:input_line[:11] == 'COMPLETION: '
  126. let l:value = l:input_line[12:]
  127. " Chop off anything after " : ", if present, and move it to the menu.
  128. let l:menu = ""
  129. let l:spacecolonspace = stridx(l:value, " : ")
  130. if l:spacecolonspace != -1
  131. let l:menu = l:value[l:spacecolonspace+3:]
  132. let l:value = l:value[:l:spacecolonspace-1]
  133. endif
  134. " Chop off " (Hidden)", if present, and move it to the menu.
  135. let l:hidden = stridx(l:value, " (Hidden)")
  136. if l:hidden != -1
  137. let l:menu .= " (Hidden)"
  138. let l:value = l:value[:l:hidden-1]
  139. endif
  140. " Handle "Pattern". TODO: Make clang less weird.
  141. if l:value == "Pattern"
  142. let l:value = l:menu
  143. let l:pound = stridx(l:value, "#")
  144. " Truncate the at the first [#, <#, or {#.
  145. if l:pound != -1
  146. let l:value = l:value[:l:pound-2]
  147. endif
  148. endif
  149. " Filter out results which don't match the base string.
  150. if a:base != ""
  151. if l:value[:strlen(a:base)-1] != a:base
  152. continue
  153. end
  154. endif
  155. " TODO: Don't dump the raw input into info, though it's nice for now.
  156. " TODO: The kind string?
  157. let l:item = {
  158. \ "word": l:value,
  159. \ "menu": l:menu,
  160. \ "info": l:input_line,
  161. \ "dup": 1 }
  162. " Report a result.
  163. if complete_add(l:item) == 0
  164. return []
  165. endif
  166. if complete_check()
  167. return []
  168. endif
  169. elseif l:input_line[:9] == "OVERLOAD: "
  170. " An overload candidate. Use a crazy hack to get vim to
  171. " display the results. TODO: Make this better.
  172. let l:value = l:input_line[10:]
  173. let l:item = {
  174. \ "word": " ",
  175. \ "menu": l:value,
  176. \ "info": l:input_line,
  177. \ "dup": 1}
  178. " Report a result.
  179. if complete_add(l:item) == 0
  180. return []
  181. endif
  182. if complete_check()
  183. return []
  184. endif
  185. endif
  186. endfor
  187. return []
  188. endfunction ClangComplete
  189. " This to enables the somewhat-experimental clang-based
  190. " autocompletion support.
  191. set omnifunc=ClangComplete