Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Reverse selected text
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Reverse selected text
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=223 |previous=222 |next=224 |created=2002 |complexity=basic |author=scott urban |version=5.7 |rating=8/5 |category1= |category2= }} Suppose you want to reverse some text. This mapping will reverse visually selected text. Put the mapping in your vimrc or otherwise source it, then visually select the word or words, and type <code>;rv</code> β really only works with selections on one line: <pre> vnoremap ;rv c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR> </pre> ==Comments== Interesting idea, but it will only work for those whose Vim has the +rightleft option. For those who don't have such a Vim, use "ma" to (mark a) and move the cursor to the last line to be affected, and: <pre> " \fr: reverse the order of lines (vertical mirror) nmap \fr :set lz<CR>o<Esc>mz'aO<Esc>ma:'a+1,'z-1g/^/m 'a<CR>'addma'zdd:set nolz<CR> " \fR: mirror image the lines (horizontal mirror) nmap \fR :set lz<CR>o<Esc>mzkO<Esc>maj:s/./&\r/g<CR>:'a+1,'z-1g/^/m 'a<CR>:'a+1,'z-1j!<CR>'add'zddk:set nolz<CR> </pre> TIMTOWTDI: Here's a simpler approach for the horizontal mirror, and a command thrown in as a bonus: <pre> nmap \fR :Mirror<CR> command! -bar -range Mirror <line1>,<line2>call setline('.', join(reverse(split(getline('.'), '\zs')), '')) </pre> TIMTOWTDI: Here's a simpler approach for the vertical mirror: <pre> map \fr :Reverse<CR> sunmap \fr ounmap \fr command! -bar -range=% Reverse <line1>,<line2>g/^/m<line1>-1 </pre> Notice it was mapped then had specific sections unmapped since they don't make sense to have them. ---- I use it in my work to reverse the order of 1000 groups of parameters which improves the program performance. Thanks.
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab