Vim Tips Wiki

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

1,626pages on
this wiki
Add New Page
Talk0 Share
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"
  let column = col(".")
  let line_len = strlen (line)
  let first_or_end=0
  if column == 1
    let first_or_end=1
    if column == line_len
      let first_or_end=1
  execute "normal i\<DEL>\<Esc>"
  if first_or_end == 0
    execute "normal l"
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.


I made a real script from this: cr-bs-del-space-tab.vim script#1579

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.