I have a file where I have multiple lines. Is there an option in Sublime Text 3 to reverse whole line ? Like
ABCDEFG
to
GFEDCBA
12345
67890
abcde
|
to
|
v
abcde
67890
12345
click Edit---->Permute lines--->Reverse and it will reverse all lines you selected in a file.
You best bet would definitely to take Leonid's advice and use a different tool, but if you are curious as to how one might do that in Sublime you have two options.
First go to Tools->New Plugin and paste the following code into the file:
import sublime, sublime_plugin
class ReverseCharactersCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
stringContents = self.view.substr(region)
self.view.replace(edit, region, stringContents[::-1])
Following that select the different sections of the document that you want reversed and run the follow command from the console
view.run_command("reverse_characters")
Here is an image of that workflow.
The import section of that code is the:
stringContents[::-1]
Which is an idiomatic way of reversing a string in Python.
Alternatively you could go checkout this follow git repository and which has the same code and a convenient command palette options specified for you :)
https://github.com/MattSeen/ST_ReverseCharacters
In vanilla sublime:
.
and click "Find all" (⌥+Enter)
Edit > Permute selections > Reverse
It's not elegant but it is straightforward and repeatable. If you already have the cursors, all you need is step 4.
Not inside Sublime Text, but in Linux/OSX the rev command-line utility does just that - rev file.txt
reverses every line of the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With