Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I am trying to reverse a string, so that 'abc defg hij' becomes 'jih gfed cba'. The solution I came up with is
'abc defg hij'
'jih gfed cba'
join(reverse(split(l:text, '.\zs')), '')
Is there a more elegant solution or should I stick with what I have come up with?
Your solution is very elegant! An alternative if you are in Unix based env:
vnoremap <Leader>r c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR>
For more see: :h revins
If you are using a unix-like system, in vim, type ex-command
Required, but never shown