Wikia

Vim Tips Wiki

Changes: Trailing white space aware Delete key

Edit

Back to page

(Remove html character entities)
(adjust previous/next navigation + minor manual clean)
 
Line 3: Line 3:
 
|id=1389
 
|id=1389
 
|previous=1388
 
|previous=1388
|next=1390
+
|next=1391
|created=November 16, 2006
+
|created=2006
 
|complexity=basic
 
|complexity=basic
 
|author=pulp
 
|author=pulp
|version=5.7
+
|version=6.0
 
|rating=77/22
 
|rating=77/22
 
|category1=
 
|category1=

Latest revision as of 10:20, April 23, 2011

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)
  endif
  iunmap <silent> <DEL>
  execute "normal i\<DEL>\<Esc>"
  if column > 1
    execute "normal l"
  endif
  inoremap <silent> <DEL> <C-o>: call Smart_Del()<CR>
endfunction
inoremap <silent> <DEL> <C-o>: call Smart_Del()<CR>

CommentsEdit

Around Wikia's network

Random Wiki