Reputation: 5030
I have an issue that is driving me insane with Sublime Text 3. When I select multiple lines by clicking on the side of the line and dragging, I then hit tab to correct the indentation, but then I want to move the entire line to another spot except I have to re-select it because the first line is only selected from where the text starts, not where the line starts.
Let's see if I can illustrate this... Below is the lines I have:
Text Line 1
Text Line 2
I select them (selection shown using *)
*Text Line 1
Text Line 2*
I indent the lines and now the selection looks like this:
*Text Line1
Text Line 2*
Notice the selection starts with the text. I want the selection to stay at the beginning of the line like this:
* Text Line 1
Text Line 2*
I have searched everywhere but apparently I'm the only one that is bothered by this. Every other code editor I have used does it the way I want.
Upvotes: 3
Views: 613
Reputation: 9986
There is a plugin called FixSelectionAfterIndent, I just found it (again) because SublimeText4 has the same problem and I already forgot how I fixed it in ST3. So anyone looking for a solution to this (veeeeeeeery annoying) problem, here it is. (You can install it via Package Control, but I like to put links in my answers, for no particular reason.)
https://packagecontrol.io/packages/FixSelectionAfterIndent
Upvotes: 1
Reputation: 16095
You can achieve this will a small Python plugin:
Replace the contents with the following:
import sublime
import sublime_plugin
class IndentSelectWholeFirstLineEventListener(sublime_plugin.EventListener):
def on_post_text_command(self, view, command_name, args):
if command_name == 'indent':
if all(not sel.empty() for sel in view.sel()):
if all(view.line(sel.begin()) != view.line(sel.end()) for sel in view.sel()):
new_selections = []
for sel in view.sel():
new_selections.append(sel.cover(view.line(sel.begin())))
view.sel().clear()
view.sel().add_all(new_selections)
fix_selection_after_indent.py
How this works:
Immediately after the indent
command is executed, if all the selections are not empty, and they all span multiple lines, extend the selections to cover the entire first line of each selection.
Upvotes: 4