Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " My solution to reident, remove duplicated blank lines and things like that
- " envoles the function Preserve(), it allows me doing a lot of stuff withou moving
- " my cursor or messing up with my jumps and search registers
- " Utility function that save last search and cursor position
- " http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
- " video from vimcasts.org: http://vimcasts.org/episodes/tidying-whitespace
- " using 'execute' command doesn't overwrite the last search pattern, so I
- " don't need to store and restore it.
- " preserve function
- if !exists('*Preserve')
- function! Preserve(command) range
- try
- let l:win_view = winsaveview()
- silent! keepjumps keeppatterns execute a:command
- finally
- call winrestview(l:win_view)
- endtry
- endfunction
- endif
- " remove consecutive blank lines
- " see Preserve function definition
- fun! DelBlankLines() range
- if !&binary && &filetype != 'diff'
- call Preserve(':%s/\s\+$//e')
- call Preserve(':%s/^\n\{2,}/\r/ge')
- endif
- endfun
- command! -nargs=0 DelBlank :call DelBlankLines()
- nnoremap <Leader>d :call DelBlankLines()<cr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement