2014-12-09 13:45:47 +00:00
|
|
|
" Code formatting settings for Vim.
|
|
|
|
"
|
|
|
|
" To enable this for GCC files by default, you can either source this file
|
|
|
|
" in your .vimrc via autocmd:
|
|
|
|
" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc
|
|
|
|
" or source the script manually for each newly opened file:
|
|
|
|
" :so contrib/vimrc
|
|
|
|
" You could also use numerous plugins that enable local vimrc e.g.
|
|
|
|
" mbr's localvimrc or thinca's vim-localrc (but note that the latter
|
|
|
|
" is much less secure). To install local vimrc config, run
|
|
|
|
" $ make vimrc
|
|
|
|
" from GCC build folder.
|
|
|
|
"
|
2024-01-03 11:19:35 +00:00
|
|
|
" Copyright (C) 2014-2024 Free Software Foundation, Inc.
|
2014-12-09 13:45:47 +00:00
|
|
|
"
|
|
|
|
" This program is free software; you can redistribute it and/or modify
|
|
|
|
" it under the terms of the GNU General Public License as published by
|
|
|
|
" the Free Software Foundation; either version 3 of the License, or
|
|
|
|
" (at your option) any later version.
|
|
|
|
"
|
|
|
|
" This program is distributed in the hope that it will be useful,
|
|
|
|
" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
" GNU General Public License for more details.
|
|
|
|
"
|
|
|
|
" You should have received a copy of the GNU General Public License
|
|
|
|
" along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
function! SetStyle()
|
|
|
|
let l:fname = expand("%:p")
|
2020-04-17 06:55:55 +00:00
|
|
|
let l:ext = fnamemodify(l:fname, ":e")
|
|
|
|
let l:c_exts = ['c', 'h', 'cpp', 'cc', 'C', 'H', 'def', 'java']
|
2014-12-09 13:45:47 +00:00
|
|
|
if stridx(l:fname, 'libsanitizer') != -1
|
|
|
|
return
|
|
|
|
endif
|
2020-04-17 06:55:55 +00:00
|
|
|
if l:ext != "py"
|
|
|
|
setlocal tabstop=8
|
|
|
|
setlocal softtabstop=2
|
|
|
|
setlocal shiftwidth=2
|
|
|
|
setlocal noexpandtab
|
|
|
|
endif
|
2020-05-13 12:58:26 +00:00
|
|
|
if &filetype == "gitcommit"
|
|
|
|
setlocal textwidth=72
|
|
|
|
else
|
2021-07-20 10:06:01 +00:00
|
|
|
setlocal textwidth=79
|
2020-05-13 12:58:26 +00:00
|
|
|
endif
|
2019-09-02 12:30:02 +00:00
|
|
|
setlocal formatoptions-=ro formatoptions+=cqlt
|
2020-07-23 14:38:58 +00:00
|
|
|
if index(l:c_exts, l:ext) != -1 || &filetype == "c" || &filetype == "cpp"
|
2014-12-09 13:45:47 +00:00
|
|
|
setlocal cindent
|
|
|
|
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call SetStyle()
|