Home | History | Annotate | Line # | Download | only in contrib
      1      1.1  mrg " Code formatting settings for Vim.
      2      1.1  mrg "
      3      1.1  mrg " To enable this for GCC files by default, you can either source this file
      4      1.1  mrg " in your .vimrc via autocmd:
      5      1.1  mrg "   :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc
      6      1.1  mrg " or source the script manually for each newly opened file:
      7      1.1  mrg "   :so contrib/vimrc
      8      1.1  mrg " You could also use numerous plugins that enable local vimrc e.g.
      9      1.1  mrg " mbr's localvimrc or thinca's vim-localrc (but note that the latter
     10      1.1  mrg " is much less secure). To install local vimrc config, run
     11      1.1  mrg "   $ make vimrc
     12      1.1  mrg " from GCC build folder.
     13      1.1  mrg " 
     14  1.1.1.5  mrg " Copyright (C) 2014-2024 Free Software Foundation, Inc.
     15      1.1  mrg "
     16      1.1  mrg " This program is free software; you can redistribute it and/or modify
     17      1.1  mrg " it under the terms of the GNU General Public License as published by
     18      1.1  mrg " the Free Software Foundation; either version 3 of the License, or
     19      1.1  mrg " (at your option) any later version.
     20      1.1  mrg "
     21      1.1  mrg " This program is distributed in the hope that it will be useful,
     22      1.1  mrg " but WITHOUT ANY WARRANTY; without even the implied warranty of
     23      1.1  mrg " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24      1.1  mrg " GNU General Public License for more details.
     25      1.1  mrg "
     26      1.1  mrg " You should have received a copy of the GNU General Public License
     27      1.1  mrg " along with this program.  If not, see <http://www.gnu.org/licenses/>.
     28      1.1  mrg 
     29      1.1  mrg function! SetStyle()
     30      1.1  mrg   let l:fname = expand("%:p")
     31  1.1.1.3  mrg   let l:ext = fnamemodify(l:fname, ":e")
     32  1.1.1.3  mrg   let l:c_exts = ['c', 'h', 'cpp', 'cc', 'C', 'H', 'def', 'java']
     33      1.1  mrg   if stridx(l:fname, 'libsanitizer') != -1
     34      1.1  mrg     return
     35      1.1  mrg   endif
     36  1.1.1.3  mrg   if l:ext != "py"
     37  1.1.1.2  mrg     setlocal tabstop=8
     38      1.1  mrg     setlocal softtabstop=2
     39  1.1.1.2  mrg     setlocal shiftwidth=2
     40  1.1.1.2  mrg     setlocal noexpandtab
     41  1.1.1.3  mrg   endif
     42  1.1.1.4  mrg   if &filetype == "gitcommit"
     43  1.1.1.4  mrg     setlocal textwidth=72
     44  1.1.1.4  mrg   else
     45  1.1.1.4  mrg     setlocal textwidth=79
     46  1.1.1.4  mrg   endif
     47  1.1.1.3  mrg   setlocal formatoptions-=ro formatoptions+=cqlt
     48  1.1.1.4  mrg   if index(l:c_exts, l:ext) != -1 || &filetype == "c" || &filetype == "cpp"
     49  1.1.1.3  mrg     setlocal cindent
     50      1.1  mrg     setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0
     51      1.1  mrg   endif
     52      1.1  mrg endfunction
     53      1.1  mrg 
     54      1.1  mrg call SetStyle()
     55