Wikia

Vim Tips Wiki

Use Return and Delete keys in normal mode like in insert mode

Talk0
1,610pages on
this wiki
Revision as of 09:21, April 25, 2008 by JohnBot (Talk | contribs)

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


Advertisement | Your ad here

Around Wikia's network

Random Wiki