Fandom

Vim Tips Wiki

Reverse letters

1,624pages on
this wiki
Add New Page
Talk0 Share
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>

CommentsEdit

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:set nolz<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.