Vim Tips Wiki
mNo edit summary
m (Fix 'x' command in virtualedit mode (past end-of-file) moved to Fix the x command in virtualedit mode: Page moved by JohnBot to improve title)

Revision as of 09:51, 18 October 2007

Previous TipNext Tip

Tip: #734 - Fix the x command in virtualedit mode

Created: May 27, 2004 13:14 Complexity: basic Author: Yakov Lerner Version: 6.0 Karma: -1/1 Imported from: Tip#734

This tip is useful only for those who use virtualedit mode (set virtualedit=all, or set ve=all).

I like virtualedit mode except for behaviour of 'x' (delete character). When 'x' is used past end-of-line, it does nothing. I wanted it to jump left to the actual end-of-line so as to start deleting characters there. Below is 'x' redefinition that does exactly this; and it does not break 'x' in non-virtualedit mode:

" redefine x for virtualEdit so that past end of line, it jumps left to end-of-line 
function! Redefine_x_ForVirtualEdit() 
  if &ve != "" && col('.') >= col('$') 
    normal $ 
  endif 
endfu! 
silent! unmap x 
:nnoremap <silent>x x:call Redefine_x_ForVirtualEdit()<cr>

Comments