Vim Tips Wiki
No edit summary
 
(Change <tt> to <code>, perhaps also minor tweak.)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=734
 
|id=734
  +
|previous=733
|title=fix 'x' command in virtualedit mode (past end-of-file)
 
  +
|next=735
|created=May 27, 2004 13:14
+
|created=2004
 
|complexity=basic
 
|complexity=basic
 
|author=Yakov Lerner
 
|author=Yakov Lerner
 
|version=6.0
 
|version=6.0
 
|rating=-1/1
 
|rating=-1/1
  +
|category1=
|text=
 
  +
|category2=
This tip is useful only for those who use virtualedit mode (set virtualedit=all, or set ve=all).
 
 
}}
 
This tip is useful only for those who use virtualedit mode (<code>set virtualedit=all</code>, or <code>set ve=all</code>).
   
  +
I like virtualedit mode except for behaviour of '<code>x</code>' (delete character). When '<code>x</code>' 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 '<code>x</code>' redefinition that does exactly this; and it does not break '<code>x</code>' in non-virtualedit mode:
   
  +
<pre>
 
" 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>
  +
</pre>
   
 
==Comments==
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 &amp;ve != "" &amp;&amp; col('.') &gt;= col('$')
 
 
normal $
 
 
endif
 
 
endfu!
 
 
silent! unmap x
 
 
:nnoremap &lt;silent&gt;x x:call Redefine_x_ForVirtualEdit()&lt;cr&gt;
 
 
 
 
 
}}
 
 
== Comments ==
 
<!-- parsed by vimtips.py in 0.428693 seconds-->
 

Latest revision as of 05:45, 13 July 2012

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

Comments[]