diff --git a/README.md b/README.md new file mode 100644 index 0000000..02b48fd --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +EmptyLines +========== + +A quick VIM plugin for adding/removing empty lines around code. +Install it using Vundle. Example configuration: + + nnoremap :call DelEmptyLineAbove() + nnoremap :call AddEmptyLineAbove() + nnoremap :call DelEmptyLineBelow() + nnoremap :call AddEmptyLineBelow() diff --git a/plugin/emptyLines.vim b/plugin/emptyLines.vim new file mode 100644 index 0000000..006c35b --- /dev/null +++ b/plugin/emptyLines.vim @@ -0,0 +1,40 @@ +function! DelEmptyLineAbove() + if line(".") == 1 + return + endif + let l:line = getline(line(".") - 1) + if l:line =~ '^\s*$' + let l:colsave = col(".") + .-1d + silent normal! + call cursor(line("."), l:colsave) + endif +endfunction + +function! AddEmptyLineAbove() + let l:scrolloffsave = &scrolloff + " Avoid jerky scrolling with ^E at top of window + set scrolloff=0 + call append(line(".") - 1, "") + if winline() != winheight(0) + silent normal! + endif + let &scrolloff = l:scrolloffsave +endfunction + +function! DelEmptyLineBelow() + if line(".") == line("$") + return + endif + let l:line = getline(line(".") + 1) + if l:line =~ '^\s*$' + let l:colsave = col(".") + .+1d + '' + call cursor(line("."), l:colsave) + endif +endfunction + +function! AddEmptyLineBelow() + call append(line("."), "") +endfunction