Sublime Forum

Question about specific text operation in Sublime

#1

Hello,

Couple days ago I stumbled upon simple task: reverse a given string. For example word: ‘uncle’ convert to ‘elcnu’.
I always knew that Sublime has command ‘Permute Lines: Reverse’ but that’s not what I thought is.
Is this a hidden feature of Sublime and I don’t see it? Unfortunately there is no additional packages I can find to perform this task either :-/

Any help how to use Sublime to advance text manipulations?

0 Likes

#2

https://packagecontrol.io/packages/TransposeCharacter
Disclaimer: I did not try it.


Or, write your own plugin.

ReverseSelectedString.py

import sublime
import sublime_plugin


class ReverseSelectedStringCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        v = self.view
        for region in v.sel():
            if region.empty():
                region = v.word(region)
            v.replace(edit, region, v.substr(region)[::-1])

keybinding

{ "keys": ["WHATEVER"], "command": "reverse_selected_string" },
1 Like