Vim Tips Wiki

Fix the x command in virtualedit mode

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 734 Printable Monobook Previous Next

created 2004 · complexity basic · author Yakov Lerner · version 6.0

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 $
silent! unmap x
:nnoremap <silent>x x:call Redefine_x_ForVirtualEdit()<CR>


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.

Also on Fandom

Random Wiki