.*\n.*\n
You can do it easily :
EDIT :
(.*(\n|$)){2}
expressionI was searching for a way to select alternate lines in sublime.
Thanks to Joe Daley for a very good answer. Though I realised that, if you use regex it would not select the last line in the file if there is no new-line at the end of the file.
I wanted to improve that answer but I don't seem to have enough reputation at the moment to comment on the answer above.
You can use the following search string with the regex turned on, and then press alt+enter. Followed by a left arrow. This would put a cursor each on alternate lines (same steps as explained by Joe Daley)
^.*\n.*$
You can try with a plugin: Tools/New Plugin...
import sublime_plugin
class ExpandSelectionToOtherLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command("expand_selection", {"to": "line"})
start_region = self.view.sel()[0]
self.view.window().run_command("select_all")
self.view.sel().subtract(start_region)
Save this file in your Packages/User
.
Then, add the key binding for that plugin:
{ "keys": ["super+alt+l"], "command": "expand_selection_to_other_lines" }
This command will select all other lines. When you have other lines selected, you can use Split selection into lines
command (Ctrl+Shift+L, Cmd+Shift+L on Mac).
If you want to have everythnig in a single shortcut, you can modify the plugin like this:
import sublime_plugin
class ExpandSelectionToOtherLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command("expand_selection", {"to": "line"})
start_region = self.view.sel()[0]
self.view.window().run_command("select_all")
self.view.sel().subtract(start_region)
self.view.window().run_command("split_selection_into_lines")
self.view.window().run_command("move", {"by": "characters", "forward": False})
The last line is only to remove selection, leaving multiple cursors at the beginning of selected lines.
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