Vim Tips Wiki
(Change to TipImported template + severe manual clean)
(→‎Comments: corrected cmd line option --versions to --version)
Tag: Visual edit
 
(3 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
|previous=711
 
|previous=711
 
|next=713
 
|next=713
|created=May 6, 2004
+
|created=2004
 
|complexity=basic
 
|complexity=basic
 
|author=David Fishburn
 
|author=David Fishburn
 
|version=5.7
 
|version=5.7
 
|rating=1/3
 
|rating=1/3
  +
|category1=
  +
|category2=
 
}}
 
}}
Simply enable visual mode (v), highlight the characters you want inverted, and hit <tt>\is</tt>.
+
Simply enable visual mode (v), highlight the characters you want inverted, and hit <code>\is</code>.
   
For a single word you can use <tt>vw</tt> (or <tt>viw</tt>):
+
For a single word you can use <code>vw</code> (or <code>viw</code>):
 
<pre>
 
<pre>
 
viw\is
 
viw\is
Line 18: Line 20:
   
 
<pre>
 
<pre>
vnoremap &lt;silent&gt; &lt;Leader&gt;is :&lt;C-U&gt;let old_reg_a=@a&lt;cr&gt;
+
vnoremap <silent> <Leader>is :<C-U>let old_reg_a=@a<CR>
\:let old_reg=@"&lt;cr&gt;
+
\:let old_reg=@"<CR>
 
\gv"ay
 
\gv"ay
 
\:let @a=substitute(@a, '.\(.*\)\@=',
 
\:let @a=substitute(@a, '.\(.*\)\@=',
\ '\=@a[strlen(submatch(1))]', 'g')&lt;cr&gt;
+
\ '\=@a[strlen(submatch(1))]', 'g')<CR>
\gvc&lt;C-R&gt;a&lt;ESC&gt;
+
\gvc<C-R>a<Esc>
\:let @a=old_reg_a&lt;cr&gt;
+
\:let @a=old_reg_a<CR>
\:let @"=old_reg&lt;cr&gt;
+
\:let @"=old_reg<CR>
 
</pre>
 
</pre>
   
 
==Comments==
 
==Comments==
If your Vim has +rightleft (check vim --versions), the following visual mode map does the job:
+
If your Vim has +rightleft (check vim --version), the following visual mode map does the job:
vmap &lt;Leader&gt;fR c&lt;C-O&gt;:set ri&lt;cr&gt;&lt;C-R&gt;"&lt;esc&gt;:set nori&lt;cr&gt;
+
vmap <Leader>fR c<C-O>:set ri<CR><C-R>"<Esc>:set nori<CR>
   
 
A map that reverses the sequence of lines (again, visual mode):
 
A map that reverses the sequence of lines (again, visual mode):
vmap &lt;Leader&gt;fr :&lt;c-u&gt;set lz&lt;CR&gt;'&gt;o&lt;Esc&gt;'&lt;O&lt;Esc&gt;V'&gt;j:&lt;c-u&gt;'&lt;+1,'&gt;-1g/^/m '&lt;&lt;CR&gt;'&lt;dd'&gt;dd:set nolz&lt;CR&gt;
+
vmap <Leader>fr :<c-u>set lz<CR>'>o<Esc>'<O<Esc>V'>j:<c-u>'<+1,'>-1g/^/m '<<CR>'<dd'>dd:set nolz<CR>
   
 
----
 
----

Latest revision as of 10:33, 7 October 2014

Tip 712 Printable Monobook Previous Next

created 2004 · complexity basic · author David Fishburn · version 5.7


Simply enable visual mode (v), highlight the characters you want inverted, and hit \is.

For a single word you can use vw (or viw):

viw\is
vnoremap <silent> <Leader>is :<C-U>let old_reg_a=@a<CR>
 \:let old_reg=@"<CR>
 \gv"ay
 \:let @a=substitute(@a, '.\(.*\)\@=',
 \ '\=@a[strlen(submatch(1))]', 'g')<CR>
 \gvc<C-R>a<Esc>
 \:let @a=old_reg_a<CR>
 \:let @"=old_reg<CR>

Comments[]

If your Vim has +rightleft (check vim --version), the following visual mode map does the job:

vmap <Leader>fR c<C-O>:set ri<CR><C-R>"<Esc>:set nori<CR>

A map that reverses the sequence of lines (again, visual mode):

vmap <Leader>fr :<c-u>set lz<CR>'>o<Esc>'<O<Esc>V'>j:<c-u>'<+1,'>-1g/^/m '<<CR>'<dd'>dd:set nolz<CR>