Wikia

Vim Tips Wiki

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

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 29: Line 29:
 
endif
 
endif
 
endif
 
endif
execute "normal i\<DEL>\<ESC>"
+
execute "normal i\<DEL>\<Esc>"
 
if first_or_end == 0
 
if first_or_end == 0
 
execute "normal l"
 
execute "normal l"
 
endif
 
endif
 
endfunction
 
endfunction
nnoremap &lt;silent&gt; &lt;DEL&gt; :call Delete_key()&lt;CR&gt;
+
nnoremap <silent> <DEL> :call Delete_key()<CR>
nnoremap &lt;silent&gt; &lt;CR&gt; i&lt;CR&gt;&lt;ESC&gt;
+
nnoremap <silent> <CR> i<CR><Esc>
 
</pre>
 
</pre>
   

Latest revision as of 00:08, September 30, 2008

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.

CommentsEdit

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


Around Wikia's network

Random Wiki