Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sublime text multiple cursor shortcut

I'm a huge user of emacs and I absolutly love the fact that you can do EVERYTHING without using the mouse. I thing that feature make emacs really efficient.

I'm also a big fan of Sublime Text on Linux. I like the multiple cursor feature that you enable with Ctrl+left_mouse_clik. I also found that you can click Shift+alt+arrow_up_or_down which create a new cursor on the above or below line. So I was wondering if there was a way in sublime text to create multiple cursor wherever you want without using the mouse.

like image 947
Adam Sinclair Avatar asked Sep 13 '14 20:09

Adam Sinclair


People also ask

How do I get multiple cursors?

A common way to add more cursors is with Shift+Alt+Down or Shift+Alt+Up that insert cursors below or above. Note: Your graphics card driver (for example NVIDIA) might overwrite these default shortcuts. Ctrl+D selects the word at the cursor, or the next occurrence of the current selection.

How do I type multiple lines in Sublime Text?

To select multiple regions using the keyboard, select a block of text, then press Ctrl+Shift+L to split it into one selection per line. When you're done with using multiple selections, just press Ctrl+K to trim all but the first.

What is Ctrl D in sublime?

Ctrl + D in SublimeText is "Quick Add Next." This appears to be equivalent to Ctrl + B in Brackets, which is "Add next match to Selection" on the Find menu.


2 Answers

One possible solution is to use bookmarks (if you aren't already). I don't know the Linux key bindings off the top of my head, but you can add bookmarks, then select all. To view the bindings for your platform, go to Goto -> Bookmarks, they should be listed by the command. You can also take a look at the default key binding file.

A second solution is to use a plugin. I wrote the following a while ago. Can't really say if/how well it works, as I can't remember. A quick test with it leads me to believe it works okay.

import sublime
import sublime_plugin


class MultiCursorCommand(sublime_plugin.TextCommand):
    def run(self, edit, action="add"):
        self.key = "multi_cursor"
        cursors = self.view.sel()
        saved_cursors = self.view.get_regions(self.key)
        if action == "add":
            self.view.add_regions(self.key, list(cursors) + saved_cursors, "keyword", "", sublime.DRAW_EMPTY)
        elif action == "show":
            cursors.add_all(saved_cursors)
            self.view.add_regions(self.key, [])
        elif action == "show_begin":
            saved_cursors += list(cursors)
            cursors.clear()
            cursors.add_all([c.begin() for c in saved_cursors])
            self.view.add_regions(self.key, [])
        elif action == "show_end":
            saved_cursors += list(cursors)
            cursors.clear()
            cursors.add_all([c.end() for c in saved_cursors])
            self.view.add_regions(self.key, [])
        elif action == "show_visible":
            pass
        elif action == "clear":
            self.view.add_regions(self.key, [])
        elif action == "remove":
            for cursor in cursors:
                if cursor in saved_cursors:
                    saved_cursors.remove(cursor)
            self.view.add_regions(self.key, saved_cursors, "keyword", "", sublime.DRAW_EMPTY)


class RemoveCursorCommand(sublime_plugin.TextCommand):
    def is_enabled(self):
        return len(self.view.sel()) > 1

    def run(self, edit, forward=True):
        self.view.sel().subtract(self.view.sel()[0 if forward else -1])

Key bindings will look something like

{ "keys": ["alt+a"], "command": "multi_cursor", "args": {"action": "add"} },
{ "keys": ["alt+s"], "command": "multi_cursor", "args": {"action": "show"} }

There are probably plugins that people have written that are on package control that do the same thing, I'm just not aware of them.

like image 129
skuroda Avatar answered Oct 01 '22 20:10

skuroda


I think PowerCursors is what you're looking for

https://packagecontrol.io/packages/PowerCursors

like image 26
somedirection Avatar answered Oct 01 '22 20:10

somedirection