Tip 1389 Printable Monobook Previous Next

created 2006 · complexity basic · author pulp · version 6.0

This function will extend the 'delete key' to delete trailing white spaces and empty lines at once. Leading blanks are preserved.

Tested with: Insert Mode, set virtualedit=all, set backspace=2, blanks for ident.

function! Smart_Del(...)
  let line=getline (".")
  let column = col(".")
  let part2= strpart(line, column-1)
  if part2 =~ '^\s*$' && part2!=""
    let part1= strpart(line, 0, column-1)
    call setline (".", part1)
  iunmap <silent> <DEL>
  execute "normal i\<DEL>\<Esc>"
  if column > 1
    execute "normal l"
  inoremap <silent> <DEL> <C-o>: call Smart_Del()<CR>
inoremap <silent> <DEL> <C-o>: call Smart_Del()<CR>


Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.