Sublime Forum

Sublemacs Pro - Emacs mode for Sublime Text

#1

While Sublime Text is an awesome text editor the keybindings provided are not necessarily optimal for my workflow. After years of training my muscle memories to retain the movements and behavioral shortcuts of Emacs I still want to use Sublime but keep my productivity. Therefore I wrote Sublemacs which is an Emacs mode for Sublime as Vintage is an VI mode for Sublime.

It currently supports most of the Emacs shortcuts with the visual sugar of Sublime Text. For example it supports the following additions to the standard features of Sublime:

  • Kill line, region … with kill ring. All the sugar you love with a nice UI with M-w
    , C-w, C-y

  • Yank with free choice from kill ring using fancy overlay: Just press M-Y
    to access the kill ring and search for your last copy and pastie

  • Rectangular cut and insert using C-x r t
    and C-x r d

  • Named registers to store data using C-x r s
    [register] and C-x r i [register]

  • Open a new line by C+o

  • C+s
    and C+r work like expected from Emacs with repeatedly pressing C+s for navigating to the next occurrence

  • C+g
    will try to exit any kind of overlays, exit snippet mode etc

  • tab
    for reindent and M+/ for auto completion

  • Using named registers for storing cursor positions across multiple views

And many more, most likely a key binding that you expect from Emacs will work as well in Sublemacs. Feel fre to checkout Sublemacs eihter directly from Github or install it via Package Control.

github.com/grundprinzip/sublemacspro

Installation: The easiest way to install is to first install Package Control (via wbond.net/sublime_packages/package_control) and then install the sublemacs package.

New:

  • Sublemacs supports both Sublime Text 2 and Sublime Text 3. If you have any recommendations for missing features from Emacs or request new features, feel free to drop me a line or open an issue on Github.

  • 03/18/2013

  • added key bindings for macro recording and fixed a bug for ST3 where goto open file would not work as expected

  • 03/18/2013

  • Paragraph Navigation is now available, but due to Mac compatibility bound to C-M and C-M ]

  • 04/11/2013

  • Added point to register and jump to point from register, search box will now disappear as soon as the focus is lost

0 Likes

Vintage -- worth retraining?
#2

I’ve been using Sublemacs for a bit and am pretty impressed overall. Here are just a couple of things that I’d like to see added:

C-x 0 — that’s a zero, not the letter O, which deletes the current window.
M-z — zap to char
M-{ and M-} — forward/backward paragraph
C-x ( and C-x ) and C-x e — Emacs-like macro keybindings
The Emacs macro counter!

Alter behavior of C-x C-f and C-x b to be a bit more like Emacs as follows (I do this on my machine)
C-x C-f — I’d prefer this to just open the dialog for the file finder
C-x b — Goto anything, which looks like a buffer list initially

Just a few things I’ve noticed in my short time trying it out. Some day maybe I’ll have enough spare time to help out rather than just complain :smiley:

0 Likes

#3

Hi,

thanks for your ideas. I quickly implemented zap-to-char so that it should be available right when PackageControl updates your plugin. In addition I added the key bindings for macro recording. With regards to C-x b, this is already implemented and should work now both in ST3 and ST2 (there was bug preventing it from working correctly in ST3).

If I find some time, I will look at paragraph navigation, unfortunately for C-x 0 I have to disappoint you, this simply does not work the way as it is done in Emacs, since ST works with layout groups instead of explicit windows, might be there is a more complicated way, but for now using the standard defined C-x 1, C-x 2, C-x 3 and C-x 5 2 are the way to go.

Thanks for your support!

0 Likes

#4

Paragraph Navigation is now available, but due to Mac compatibility bound to C-M and C-M ]

0 Likes

#5

Hi.

The C+s key binding has similar behavior to Emacs, but when the search panel loses focus, I would expect that typing C+s would bring it back into focus (and select the search text) so that you could choose to continue the search (C+s again) or type to replace the search text.

That’s what happens both in emacs and with the normal** C+f** in Sublime, but not with this package. I’m liking it otherwise!

0 Likes

#6

Ne’er mind. I discovered that C+g will cancel the current search, which is good enough for me.

0 Likes

#7

I changed the behaviour to be more Emacs like and as soon as the focus is lost from the search box the panel will disappear. This had me annoyed already so it was a must have for me :smile:

Thanks for using sublemacs.

0 Likes

#8

On the topic of incremental search, the behavior of repeated C-r is busted. When you hit C-r and start typing, focus goes to the first previous occurrence of the search text, as expected. But when you hit C-r again, it goes to the next occurrence! And if you hit C-s, it goes to the previous occurrence.

0 Likes

#9

Hi JSC,

actually this is not Sublemacs fault, but ST’s. You can validate this by opening the pristine find bar and manually clicking on the reverse button. If you then click on find it will basically find backwards, but if you click find previous it will go forward in the document. For now, I think I will make C-r open the find bar but ignore the direction so that C-r and C-s work as expected. I will post as soon as this is done.

Martin

0 Likes

#10

One more suggestion, which I’m not sure is possible, but which would be swell to have:

When you use set mark (ctrl-spc) and select a region downwards, then use shift-meta-L to split into lines, the line with the mark retains its region when you move the cursor around. So if you want to, say, add a comma to every line by hitting C-e comma, the entire first line will be replaced with a comma.

Alternatively, if you set a mark and create a region upwards, split into lines, then hit C-a or C-e, the multiple selection disappears entirely and only the marked line has a cursor.

Maybe you could, I dunno, remove the mark in that case? Not entirely sure what is to be done.

One more weirdness with marks: set a mark near the end of a file, then hit alt-shift-> to go to end of buffer. Now type C-n and C-p (or up and down arrow) and note that the cursor can no longer move past the marked line.

0 Likes

#11

I’m interested in getting the CUA mode that emacs offers which defines the standard Mac/Window key bindings:

C-x Cut to clipboard
C-c Copy to clipboard
C-v Paste from clipboard
C-z Undo
Shift-arrow Select (not as important)

Note that C-x would still work as a prefix key for other commands when no text is selected.

Any chance of getting these? Or how difficult is it for me to override sublemacs bindings?
(I imagine C-x would need to be something like a conditional macro.)

0 Likes

#12

Anyone found a way to do emacs\xemacs style autocompletion in sublime?

I don’t really care which hotkey it uses, but I have found that xemacs’s autocompletion based on proximity to be the most efficient for me and I rarely type more than 5 characters without using it. Other autocompletions such as Visual Studio or Sublime seem to put things in alphabetical order, which makes it much slower to use.

This is especially true for static globals, local variables, and parameters where the xemacs autocomplete will always guess the correct one after only 1 or 2 characters due to proximity, while sublime’s autocomplete will almost invariably default to the wrong one and require me to search through the options until I find the right one.

Another problem I have is that I don’t have autocompletion across files. I tried downloading the all autocomplete plugin and it works on my home computer, but seems to be conflicting with some other plugin and failing. Is there an error log somewhere I can check?

0 Likes

#13

Actually, just setting

“auto_complete”: false

seems to give me most of what I need. it was the popup itself that was the most irritating part.

Also, I found that I had been incorrectly using sublime_text_alternative_autocompletion. By default, it maps autocomplete to escape, which was already mapped to hide-autocomplete, thus causing it to appear to not work. It tried mapping it to tab, but it failed. When I mapped it to alt-/ I found that it works just fine.

Now I just need to figure out why I can’t get the all autocomplete plugin to work

0 Likes

#14

A couple of things I’m missing, the multi-cursor stuff already in sublime-text (default “ctrl+d” behavior, which I have user mapped to “ctrl+c”, “ctrl+d”] - there may be others (watching the video shows several features about sublime-text I hope emacs doesn’t hide/overlay))

emacs mark-sexp behavior (in emacs bound to C-M-SPC or C-M-@)

Otherwise, this is awesome!

0 Likes

#15

Firstly, thanks for this awesome plugin. I wouldn’t be using ST without it.

I noticed that when you hit C+g to cancel the current search, the cursor returns to where you initiated the search, which isn’t standard emacs behaviour. The only way around this that I’ve figured out is to click the mouse on the search match. I use search to navigate documents frequently and having to reach over to the mouse really kills my speed. Any tips to get around this? Preferably, C+g would just cancel the search and leave the cursor on the last match.

Thanks!

0 Likes

#16

Just hit return. Annoying, because I always find myself hitting ctrl g instead. Maybe a context sensitive remap of ctrl g?

0 Likes

#17

Beginner’s problem. What is the “meta” key on OS X? I think I remember where it was on a Lisp machine, but I haven’t had one of those in a while.

And how can I get an overview of the availble keybindings?

V.

0 Likes

#18

Hi, is there any way to sort list of files invoked by CTRL-x + b (goto_open_file) by last usage.

In Emacs I could always blindly press on ctrl-x + b + enter and I always was switched to the previous buffer.

Currently it is sorted by name. So, for example:

I have two files “A.ext” and “B.ext”. initially I was in “A.ext”. Then I open “B.ext” In case I’m in “B.ext” file I can press ctrl-x + b + enter I switched to “A.ext” which is exactly what I wanted. But then, if I in “A.ext” I press ctrl-x + b + enter I switched to the same file because dialog which is showing by “goto_open_file” command is sorted by name.

0 Likes