Skip to content

Commit

Permalink
That choked on big files, this works great though
Browse files Browse the repository at this point in the history
  • Loading branch information
sj26 committed Jul 26, 2017
1 parent 8f02221 commit 1ac3df5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .vim/ftplugin/ruby.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ let g:ruby_indent_block_style = 'do'

" Strip trailing empty newlines
function TrimTrailingLines()
let l:save_cursor = getpos('.')
:silent! %s#\($\n\s*\)\+\%$##
call histdel('search', -1)
call setpos('.', l:save_cursor)
let lastLine = line('$')
let lastNonblankLine = prevnonblank(lastLine)
if lastLine > 0 && lastNonblankLine != lastLine
silent! execute lastNonblankLine + 1 . ',$delete _'
endif
endfunction

autocmd BufWritePre <buffer> call TrimTrailingLines()

0 comments on commit 1ac3df5

Please sign in to comment.