Tip 1265 Printable Monobook Previous Next
created June 19, 2006 · complexity basic · author pulp · version n/a
function! Delete_key(...) let line=getline (".") if line=~'^\s*$' execute "normal dd" return endif let column = col(".") let line_len = strlen (line) let first_or_end=0 if column == 1 let first_or_end=1 else if column == line_len let first_or_end=1 endif endif execute "normal i\<DEL>\<Esc>" if first_or_end == 0 execute "normal l" endif endfunction nnoremap <silent> <DEL> :call Delete_key()<CR> nnoremap <silent> <CR> i<CR><Esc>
With this tip the keys "Return" and "Delete" will work the same in normal mode and insert mode. For example, a blank line will be deleted. Pressing Return will insert a new line.
Very useful before inserting some text via copy/paste. Or to clean up your code.
Comments[]
I made a real script from this: cr-bs-del-space-tab.vim script#1579