Add a vimrc option to force whitespace stripping in specific files
This commit is contained in:
parent
5ca7d5d5d8
commit
ed8d7bdb70
47
vimrc
47
vimrc
|
@ -81,15 +81,26 @@ let s:rainbow_theme = s:default_bg
|
||||||
" @note The following globals can be used to customize various functions in
|
" @note The following globals can be used to customize various functions in
|
||||||
" this file. The easiest way to set them is in an .lvimrc file in the root
|
" this file. The easiest way to set them is in an .lvimrc file in the root
|
||||||
" folder that you want it applied to.
|
" folder that you want it applied to.
|
||||||
"
|
|
||||||
" Set this to 0 if you want to stop the removal of trailing whitespaces.
|
" When set to 1, all files will be stripped of trailing whitespace when the
|
||||||
|
" file is saved. Set to 0 to disable. You can customize which files are
|
||||||
|
" ignored or always stripped; see below.
|
||||||
let g:campo_strip_trailing_whitespace = 1
|
let g:campo_strip_trailing_whitespace = 1
|
||||||
|
|
||||||
" If g:campo_strip_trailing_whitespace is 1 then you can stop this from
|
" If g:campo_strip_trailing_whitespace is 1 then you can stop stripping
|
||||||
" happening in specific files by setting this to a list of filenames.
|
" in specific files by setting this to a list of filenames. This has no
|
||||||
|
" effect when g:campo_strip_trailing_whitespace is 0.
|
||||||
|
"
|
||||||
" e.g. let g:campo_files_to_ignore_when_stripping_trailing_whitespace = ['app.h', 'config.h']
|
" e.g. let g:campo_files_to_ignore_when_stripping_trailing_whitespace = ['app.h', 'config.h']
|
||||||
let g:campo_files_to_ignore_when_stripping_trailing_whitespace = []
|
let g:campo_files_to_ignore_when_stripping_trailing_whitespace = []
|
||||||
|
|
||||||
|
" If g:campo_strip_trailing_whitespace is 0 then you can force whitespace
|
||||||
|
" stripping in specific files by setting this to a list of filenames. This
|
||||||
|
" has no effect when g:campo_strip_trailing_whitespace is 1.
|
||||||
|
|
||||||
|
" e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['app.h', 'config.h']
|
||||||
|
let g:campo_files_to_force_stripping_trailing_whitespace = []
|
||||||
|
|
||||||
" This is included in the ripgrep args. You can use this to do things like
|
" This is included in the ripgrep args. You can use this to do things like
|
||||||
" ignore folders in your project or limit the search to specific file types.
|
" ignore folders in your project or limit the search to specific file types.
|
||||||
" For example, if you want to ignore the 3rd_party dir and only search C files
|
" For example, if you want to ignore the 3rd_party dir and only search C files
|
||||||
|
@ -492,16 +503,28 @@ augroup campoCmds
|
||||||
|
|
||||||
" Remove trailing whitespace when saving any file.
|
" Remove trailing whitespace when saving any file.
|
||||||
function! s:StripTrailingWhitespaces()
|
function! s:StripTrailingWhitespaces()
|
||||||
if g:campo_strip_trailing_whitespace != 1
|
let l:filename = expand('%:t')
|
||||||
return
|
if g:campo_strip_trailing_whitespace == 1
|
||||||
endif
|
if len(g:campo_files_to_ignore_when_stripping_trailing_whitespace)
|
||||||
if len(g:campo_files_to_ignore_when_stripping_trailing_whitespace)
|
for ignore in g:campo_files_to_ignore_when_stripping_trailing_whitespace
|
||||||
let filename = expand('%:t')
|
if ignore == l:filename
|
||||||
for ignore in g:campo_files_to_ignore_when_stripping_trailing_whitespace
|
return
|
||||||
if filename == ignore
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
if len(g:campo_files_to_force_stripping_trailing_whitespace)
|
||||||
|
let l:found_match = 0
|
||||||
|
for name in g:campo_files_to_force_stripping_trailing_whitespace
|
||||||
|
if name == l:filename
|
||||||
|
let l:found_match = 1
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if l:found_match == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
endfor
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l = line(".")
|
let l = line(".")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user