We are huge fans of Emacs and Sublime Text. Our motivation for this project has been to bring the right amount of the Emacs experience to Sublime, while also recognizing that Sublime has some excellent ideas of its own. We appreciate the careful thought the Emacs creator put into such basic things as cursor motion, kill and mark rings, incremental search, etc. However, Sublime brings with it an extremely powerful multi-cursor concept and others which are worth embracing as well. Here we have produced a careful implementation of Emacs semantics and enhanced them with modern Sublime concepts where possible and appropriate.
- Navigation and Kill Commands for Characters/Words/Lines/S-Expressions with Multi-cursor Support
- Universal, Numeric, and Negative Argument Handling
- Kill Ring with Multi-cursor and Sublime Quick Panel Support
- Mark Ring with Multi-cursor Support
- Incremental Search with History (regular and regex supported) and Multi-cursor Features
- Frame (Window) and Window (Window Pane) Commands
- Switch to Buffer (View), Kill the Oldest Buffers, and Pinned Tabs Commands
- Change Case Commands (upper/lower/title/camelCase/under_score supported)
- Zap/Jump to Char and String with Multi-cursor Support
- Rectangle and Text/Point Register Commands (not Multi-cursor aware yet)
- All Buffers (Views) Auto Complete
The hope is that when you fire up this plugin, your fingers will find many of the key bindings and associated behavior completely familiar. We've implemented the universal argument concept (ctrl+u and meta-Digit), and made all the character, word, line and s-expression commands behave very close to the original Emacs. The ctrl+k command is identical to Emacs in almost every way, except it now includes a powerful multi-cursor implementation that makes sense. Incremental search also is very familiar, except it has additional features for keeping or skipping matches along the way, so that when you're done the "kept matches" are available as multi-cursors for further editing.
Everything else is still Sublime and all that that implies: silky smooth performance, great built-in automatic function tagging, great single-file/multi-language support, and so on.
See below for details.
To install Emacs Pro Essentials you have to install [Package Control]
(http://wbond.net/sublime_packages/package_control) as an automatic package manager for
Sublime Text. Now, you can easily install Emacs Pro Essentials and your installation will never be
outdated. After you install Package Control, hit [CMD]-Shift P
on Mac or [Ctrl]-Shift P
on Windows\Linux to open up the command palette and type install
. Now select Package Control: Install Package
. This will load all packages from the remote repository and you can
select Emacs Pro Essentials
from the drop-down list.
The main development for Emacs Pro Essentials is now Sublime Text 3 only. There is still the branch using the earlier codebase for ST2 but it honestly doesn't have most of the features mentioned.
https://github.com/sublime-emacs/sublemacspro/tree/st2
The following features have largely been implemented from scratch and are only supported with
Sublime Text 3. For the bindings below, meta
is the alt
key on Windows/Linux or the
option
key on the Mac. super
is the Command
key on the Mac.
ctrl+u
: Emacs universal argument command (so 4^n where n is the number of timesctrl+u
has been pressed) E.g.,ctrl+u ctrl+u ctrl+f
means go forward 16 characters.meta+0
...meta+9
: Emacs numeric arguments - you provide a prefix using the numeric arguments before a command to run it that many times. E.g.,meta+2 meta+3 ctrl+f
means go forward 23 characters.meta+-
: Emacs negative argument command - reverses the direction of the command. E.g.,meta+- meta+2 meta+3 ctrl+f
means go backward 23 characters.
- Commands that utilize the kill ring
ctrl+w
andmeta+w
: Kill (cut) and copy onto the kill ring.ctrl+y
: Yank (Paste) from the last entry put into the kill ring.meta+y
andshift+meta+y
: Yank-pop forward and backward from the kill ring, and requires a yank command before running either one as with Emacs.ctrl+k
: Kill to the end of line.- Mimics emacs almost exactly, killing lines and adding into the kill ring. With a
numeric argument, delete that many lines (which is different from typing
ctrl+k
that many times). Zero and negative numeric arguments also behave as expected.
- Mimics emacs almost exactly, killing lines and adding into the kill ring. With a
numeric argument, delete that many lines (which is different from typing
ctrl+meta+k
: Delete S-Expression and place onto the kill ring.- Can pass in a
direction
argument set to-1
to delete backward.
- Can pass in a
meta+d
andmeta+backspace
: Kill word forward and backward and add to the kill ring.ctrl+x ctrl+y
: Displays a Sublime quick panel menu of all the kills and allows you to choose which one to yank. If you supply a numeric argument, that means yank all the cursors into new cursors. (See below)
- Kill ring implementation details
- 64 entries by default, but settable with
sbp_kill_ring_size
setting in thesublemacspro .sublime-settings
file. - Consecutive kill commands (
meta+d
,ctrl+k
, etc.) are appended to the same entry on the kill ring so they can be yanked back as once. - The yank command will pull from the system clipboard if it finds it is not the same as
the current kill-ring entry. This means you can go into a different application and copy
something there. Then, paste it into Sublime using
ctrl+y
. - Anything you kill in Sublime will be placed on the clipboard for other apps to access. If a kill ring entry has multiple cursors, just the first cursor is placed on the clipboard.
- 64 entries by default, but settable with
- Multi-cursor support
- If you had multiple cursors while appending to the kill ring, the kill entry will contain and remember those separate cursors. If you try to yank multiple cursors, it will work as expected if you still have the same number of cursors. If you have more cursors than your kill, the kill will be repeated until you have enough. If you have fewer cursors than your kill, it will use just as many as it needs.
- If you know you want to yank all the cursors, there's a new command which will automatically
create the number of cursors you need for the kill ring entry just before it performs the
yank. This is useful if you currently have just 1 cursor but want back all the data from a
previous multi-cursor kill command. This new command is called Yank All Cursors.
Furthermore, when you supply a numeric argument to the
ctrl+x ctrl+y
command, it will let you choose which item to yank all cursors for. And now the choose command shows you which entries have more than one cursor.
- Commands that utilize the mark ring
ctrl+space
: Push a new mark onto the mark ringctrl+x ctrl+x
: Switch point and markctrl+space ctrl+space
: Push a new mark and activate the mark, which means highlight it as a selection. It will stay highlighted untilctrl+g
is pressed or certain commands are executed.ctrl+u ctrl+x ctrl+x
: Toggles the current state of the mark to see the current mark selection region. This will highlight the current mark region (activate the mark) if it isn't highlighted or remove the highlighting (deactivate the mark) if it is highlighted.- Suggested additional binding for this:
{"keys": ["ctrl+m"], "command": "sbp_swap_point_and_mark", "args": {"toggle_active_mark_mode": true}},
- Suggested additional binding for this:
ctrl+u ctrl+space
: This moves point to where the current mark is, but then rotates the mark ring so that the NEW current mark is the previous one on the ring. This allows you to move back through the mark history. Some marks are multi-cursors and they will be handled in exactly the same way.
- Mark ring implementation details
ctrl+y
sets the mark automatically as it does (and must formeta+y
to work properly) in emacs.- Commands like
meta+<
andmeta+>
also set the mark automatically. - If you use the mouse to make a selection, it will set the mark at the beginning of your selection point will be at the end, thus your emacs region and selection will be the same.
- Multi-cursor support
- You can set the mark with multiple cursors and pop off the mark ring to marks with multiple cursors. Furthermore, you can kill and copy using those cursors, and then yank them later as well.
- All the above commands for manipulating the mark ring (and kill ring) will continue to work with multiple cursors.
- Commands to initiate a search
ctrl+s
andctrl+r
: Initiate a forward or backward search.ctrl+u ctrl+s
andctrl+u ctrl+r
: Initiate a forward or backward regex search.ctrl+s ctrl+s
andctrl+r ctrl+r
: Initiate a forward or backward search using the same search string as the last search.- This can be used with a regex search as well.
- Commands during an incremental search
ctrl+s
: Move to next match.ctrl+r
: Move to previous match.meta+d
: Keep current match as a future cursor and move to next.ctrl+w
: The characters in front of your cursor are appended to your search string.meta+a
: Keep all remaining matches from your current position to the end of the file (or beginning if you're doing a reverse search). Kept matches are are saved as future cursors when isearch is done.- Pressing a second
meta+a
will wraparound, selecting all the matches in the whole file.
- Pressing a second
backspace
: Move backward in the search history (undo).- Will undo any of the above commands moving backwards in the commands run during the search one at a time. For example, it will go back to a previous match, delete a character from your search string, or remove the last kept match.
- When undoing a
ctrl+w
append from cursor command, the entire set of characters are removed at once. However, if you useshift+backspace
instead, it will remove just one character at a time.
ctrl+g
: If your search is currently failing, takes you back to the last point your search was succeeding. When your search is succeeding, the search is aborted and you go back to the start.up
: Access previous history in the search history.down
: Access next history in the search history.enter
: End your search with all the kept items as multi-cursors.
- Incremental search implementation details
- If you type any uppercase characters in your search, the search automatically becomes case-sensitive.
- You can end your search by typing any regular emacs commands as well, e.g.,
ctrl+a
,meta+f
,ctrl+l
,meta+<
,meta+>
,ctrl+f
,ctrl+n
, etc.... The kept items will be intact as multi-cursors. - When you complete (as opposed to abort) a search, your mark is set to where you started the search from.
- I-search has support for remembering previous searches. You can access previous searches with the up and down arrow keys after you initiate a search.
- Find and Replace
meta+r
: Not implemented in Emacs Pro Essentials so this brings up the default find and replace of sublime text.
- Increased Efficiencies
- If you use
alt
for the meta binding, then settingalt+s
to move to next match andalt+r
to move to previous match withalt+d
already set to keep match can make moving through iSearch quicker when selecting matches. - Example binding for
alt+r
is below (foralt+s
setforward
totrue
: {"keys": ["alt+r"], "command": "sbp_inc_search", "args": {"cmd": "next", "keep": false, "forward": false}, "context": [ {"key": "i_search_active"}, {"key": "panel_has_focus"} ] },
- If you use
- Frame (Window) Commands
ctrl+x 5 2
: Open a new frame (Window).ctrl+x 5 0
: Close the current frame (Window).
- Window Pane Commands
ctrl+x 1
: Remove all other window panes except this onectrl+x 2
: Split window pane verticallyctrl+x 3
: Split window pane horizontallyctrl+x d
: Delete current window panectrl+x o
: Go to next window pane.ctrl+x n
: Go to next window pane.ctrl+x p
: Go to previous window pane.super+shift+[
: Go to previous tab in this window pane (wraps around at edges).super+shift+]
: Go to next tab in this window pane (wraps around at edges).ctrl+x ^
orctrl+shift+i
: Make selected window pane taller.ctrl+x -
orctrl+shift+k
: Make selected window pane wider.ctrl+x }
orctrl+shift+j
: Make selected window pane narrower.ctrl+x {
orctrl+shift+l
: Make selected window pane shorter.- Resize window pane commands accept universal, numeric, and negative arguments so
meta+5 ctrl+x ^
will make the selected window taller by 5 times.
- Resize window pane commands accept universal, numeric, and negative arguments so
- View Commands
ctrl+x k
: Delete current view from this window pane.ctrl+x K
: Delete most stale n views, that is, the views that haven't been touched in the longest time (supports numeric argument input).- n is set by default to
5
. This can be changed by overriding the binding in your user bindings file by changing the argumentn_windows
. If the value is null or not specified, the numeric argument will be used to determine how many to close. The default binding is:{"keys": ["ctrl+x", "K"], "command": "sbp_close_stale_views", "args": {"n_windows": 5}}
- n is set by default to
ctrl+x P
: Pin tab. A pinned tab will never be automatically closed by thectrl+x K
command. A small pin icon (by default) will appear in the status area, settable thesbp_pinned_tab_status_text
variable.ctrl+x b
: Go to next view (keeps scrolling through all the views (tabs to the right in each window pane) and ignores window pane boundaries going into the next pane when it reaches the last view on the right).ctrl+x right
: Go to next view (set to the same command asctrl+x b
above).ctrl+x left
: Go to previous view (keeps scrolling through all the views (tabs to the left in each window pane) and ignores window pane boundaries going into the next pane when it reaches the last view on the left).
- Commands
ctrl+x ctrl+b
: Switch to a view (buffer) using the quick panel for selection.
- Implementation Details
- Sorted by last used time and skips past the current view in the quick panel to the second most recent view.
- Optional arguments with the default values are
completion_components=2
anddisplay_components=1
.- The default configuration displays the view's file name and parent directory (the last 2 components of the file path) on the top line and just the last component of the file name on the second line. The completion is performed on the first line. If you set the value of display_components to 0, the second line will be omitted entirely.
- If creating your own key bindings has optional argument
current_group_only
, default isfalse
, but when set totrue
will only use the current window pane for the switch to view.
ctrl+x ctrl+f
: Go to file in a quick panel as implemented by Sublime.ctrl+meta+g
: Go to symbol in the quick panel as implemented by Sublime.
meta+c
,meta+l
,meta+u
: capitalize, lower case, upper case words using thesbp_change_case
command. They support emacs-style numeric arguments, including negative arguments which means "do it to the previous N words".- Accepts two arguments
direction
(1
is forward and-1
is backward) andmode
(can betitle
,upper
, orlower
).
- Accepts two arguments
ctrl+x ctrl+u
andctrl+x ctrl+l
: upper case and lower case the highlighted region/s or the emacs region/s if nothing is highlighted.- This use the same
sbp_change_case
command as above with theuse_region
argument set totrue
, therefor, nodirection
argument is needed.
- This use the same
ctrl+x ctrl+meta+c
,ctrl+x ctrl+meta+u
: Convert from Underscores to camelCase and vice versa. They operate on highlighted region/s or emacs region/s asctrl+x ctrl+u
above and use the samesbp_change_case
command setting themode
tocamel
orunderscore
.
- Zap and Jump Commands
meta+z
: Zap-to-char, delete from current point to the next occurrence of a character and includes deleting the character.shift+meta+z
zap-up-to-char, delete from current point up to but not including the next occurrence of a character.ctrl+x z
zap-to-string, delete from current point until next occurrence of the string and includes deleting the string.ctrl+x Z
zap-up-to-string, delete from current point up to but not including the next occurrence of the string.ctrl+x j c
jump-to-char, move past the next occurrence of a character.ctrl+x j C
jump-up-to-char, move up to the next occurrence of a character.ctrl+x j s
jump-to-string, move past next occurrence of a string.ctrl+x j S
jump-up-to-string, move up to the next occurrence of a string.
- Implementation Details
- The char jump and zap commands have an optional argument
include_char
that is set totrue
by default. - The string jump and zap commands have an optional argument
include_string
that is set totrue
by default.
- The char jump and zap commands have an optional argument
- Text and Point Register Commands
C-x r s [register]
: Store the current emacs region or highlighted region into the register.C-x r i [register]
: Insert the selected register at the current cursor position.C-x r space [register]
: Store the current point into a register.C-x r j [register]
: Jump to the stored point in the selected register.[register]
can be set as 'a-z/0-9/A-Z'.C-x r r
: Choose a text register to insert from the sublime quick panel menu.C-x r p
: Choose a point register to jump to from the sublime quick panel menu.
- Rectangle Commands
C-x r t
: Rectangular cut (as in emacs).C-x r d
: Rectangular insert (as in emacs).
- Word Level
meta+f
andmeta+b
: Forward and backward words with the same exact behavior of emacs in terms of how you move.ctrl+meta+f
andctrl+meta+b
: Forward and backward movement over s-expressions. It works for skipping over identifiers, strings, parentheses, braces, square brackets, etc...- DEPENDENCY NOTE: S-expression checks if Bracket Highlighter is installed, which enables it to perform much better movement over s-expressions that are language dependent.
- If Bracket Highlighter isn't
installed, the s-expression falls back to default movement over the modifiers in
sbp_sexpr_separators
setting in thesublemacspro .sublime-settings
file, but this performs much worse than the updated implementation.
- Line Level
ctrl+n
: Move down a line.ctrl+p
: Move up a line.ctrl+a
: Go to beginning of line (ignores wrapped lines always goes to very beginning).meta+m
: Go back to the indentation at the beginning of the line (same asctrl+a
except moves back to the indentation instead of the very start of the line).ctrl+e
: Go to end of line (ignores wrapped lines always goes to very end).meta+a
: Go back to soft beginning of the line (doesn't ignore wrapped lines).
- Paragraph Level
ctrl+meta+]
andctrl+meta+[
: Navigate forward and backward paragraphs.
- Page Level
meta+,
andmeta+.
: Move to beginning and end of the current window view, respectively.- This command allows an optional argument
always_push_mark
which by default is set totrue
and will push the mark before going to the beginning or end of the current window view.
- This command allows an optional argument
ctrl+v
: Page down.meta+v
: Page up.ctrl+l
: Center current line in view.- Used with numeric arguments, put the current line at the Nth line in the view (E.g.
meta+5 ctrl+l
moves the current line to the 5th line in the view.
- Used with numeric arguments, put the current line at the Nth line in the view (E.g.
- File Level
meta+<
andmeta+>
: Move to beginning and end of file, respectively.meta+g
also bound toctrl+x g
: Goto line via numeric argument or via quick panel entry if entered without a numeric argument.- Numeric argument e.g.,
meta+4 meta+3 meta+5 meta+g
goes to line 435.
- Numeric argument e.g.,
- Similar to All Autocomplete plugin but fixed two issues with that plugin: the limit of 20 views to search and completions not being found due to errors in some syntax definitions.
- Disabled by default.
- Enable by setting
sbp_use_internal_complete_all_buffers
totrue
in thesublemacspro.sublime-settings
file.
- Undo/Redo
ctrl+backslash
: Undo.ctrl+_
: Undo.ctrl+x u
: Undo.ctrl+shift+/
: Redo.ctrl+shift+backslash
: Redo.
- Save
ctrl+x, ctrl+s
: Save this file.ctrl+x, ctrl+m
: Save all files.ctrl+x, s
: Save all files.ctrl+x, ctrl+w
: Prompt for writing a new file to disk (Save As...).
- Selection
ctrl+x h
: Select All (works like emacs: setting a mark at the bottom and going to the top of the file)
- Deletion
ctrl+d
: Right delete.backspace
: Left delete.
- Wrap Lines
meta+j
: Wrap lines using sublime built in function to 100 characters.
- Indent/Unindent
ctrl+c, >
: Indent.ctrl+c, <
: Unindent.meta+i
: Insert tab character at cursor ("\t").
- Macros
ctrl+x, (
: Toggle macro recording.ctrl+x, )
: Toggle macro recording.ctrl+x, e
: Execute recorded macro.
- Exit
ctrl+x, ctrl+c
: Save this file.
- Shift Indentation of Regions
meta+]
: Shift active mark region or current highlighted region to the right one indentation.meta+[
: Shift active mark region or current highlighted region to the left one indentation.
- White Space Removal
meta+backslash
: Delete white space around point (supports numeric arguments). Ifkeep_spaces
is > 0, it will leave at that many spaces instead of deleting all the white space. If a numeric argument is supplied, it overrides the keep_spaces argument.ctrl+x ctrl+o
: Delete blank lines around point.
- Auto Complete
meta+/
: Brings up Sublime's Auto Complete window.meta+h
: Brings up Sublime's Auto Complete window.
- Find and Replace
meta+r
: Not implemented so brings up default find and replace of sublime.
- Settable by
sbp_kill_ring_size
.
- Default is
sbp_use_alt_bindings
set totrue
andsbp_use_super_bindings
tofalse
.- If you prefer to use super bindings then swap these or if you prefer to have both super
and alt bindings then set both to
true
.
- If you prefer to use super bindings then swap these or if you prefer to have both super
and alt bindings then set both to
- To insert digits as their normal characters instead of using Emacs-style numeric arguments,
change
sbp_alt+digit_inserts
totrue
.
- Optional settings that if set to true in the
sublemacspro.sublime-settings
will occur on saving a file.
- Set
sbp_use_internal_complete_all_buffers
totrue
.
-
If you're running an incremental search and you invoke another command that opens the overlay, such as "Goto Anything..." or "Command Palette...", the search can get into a weird state and interfere with the overlay. To deal with that, we override the default key bindings for those commands and handle them properly. If you have your own bindings for those commands, you should copy these examples:
{"keys": ["super+shift+p"], "command": "sbp_inc_search_escape", "args": {"next_cmd": "show_overlay", "next_args": {"overlay": "command_palette"}}, "context": [ {"key": "i_search_active"}, {"key": "panel_has_focus"} ] }, {"keys": ["super+t"], "command": "sbp_inc_search_escape", "args": {"next_cmd": "show_overlay", "next_args": {"overlay": "goto", "show_files": true}}, "context": [ {"key": "i_search_active"}, {"key": "panel_has_focus"} ] },
We will try to extend this more and more to provide more features from Emacs to Sublime Text, and make this a fast and beautiful Emacs replacement.
- Supplying a numeric argument to
ctrl+d
andBackspace
should append to the kill ring. - Turn the last n marks into multiple cursors.
- Switch to view works across windows (frames) and not just within a single window.
- Make the registers work with multi-cursors.
- Emacs marking of textual objects
- Quick Panel selection to scroll through the mark ring and pop a previous mark like choose and yank command for the kill ring.
2012-2017 Jonathan Payne (@canoeberry), Jeff Spencer (@excetara2), Martin Grund (@grundprinzip), Brian M. Clapper (@bmc)
- @dustym - focus groups
- @phildopus - for goto-open-file
- @aflc - toggle comment improvements
- @jinschoi - ST3 bugfix
- @mcdonc - inspiration for more Emacs key bindings