*.rb not a file type. This is a file template. ruby is a file type and can even be installed on files that do not have the .rb extension. So what you most likely want is a function that your autorun calls to check for file types that should not be affected and separates spaces.
fun! StripTrailingWhitespace() " Don't strip on these filetypes if &ft =~ 'ruby\|javascript\|perl' return endif %s/\s\+$//e endfun autocmd BufWritePre * call StripTrailingWhitespace()
Based on evan's answer, you can check the local buffer variable and determine whether to use this strip. It will also allow you to disable one-time operation if you decide that you do not want to delete the buffer, which usually gives the file type.
fun! StripTrailingWhitespace() " Only strip if the b:noStripeWhitespace variable isn't set if exists('b:noStripWhitespace') return endif %s/\s\+$//e endfun autocmd BufWritePre * call StripTrailingWhitespace() autocmd FileType ruby,javascript,perl let b:noStripWhitespace=1
jamessan Jun 27 2018-11-18T00: 00Z
source share