You can even write your own macro implementation
SublimeText macros are no good
Yes, but recording a macro (if it work as expected) would be by far simpler than creating a plugin. I’d have to learn Python, the Sublime API, how to install and debug a plugin, …
Can I intercept all keyboard events (and forward them to their original bindings)? Or do all commands already implement a command ‘object’ (for undo/redo) that I can access from a plugin (but then: why aren’t they already recorded by the current implementation)?
You can create an EventListener
object and implement the on_text_command
and on_window_command
endpoints to capture commands as they’re happening (along with their arguments). Despite the name, on_window_command
captures ApplicationCommand
commands as well.
A simple implementation could record the commands and their arguments to replay what the user did, in theory.
In the case of Undo/Redo, that’s a function of the edit
object passed to the run
method of TextCommand
instances. The only way to modify a buffer is via a call that takes an edit
object. Under the hood Sublime uses that to track changes.
Currently only TextCommand
commands can be recorded in a macro, which is why some things don’t get recorded during Macro recording (or why you can’t manually create a macro file with those kinds of commands in it).
Only @jps knows why the current macro support only supports TextCommand
commends though.
So we are all in agreeance then…Sublime macro system sucks?
About writing my own…I don’t know anything about the api, but I am willing to be, the fact that there is no popular plugin solution probably alludes to the fact that there are some deeper rooted limitations at play here.
But sure I can write my own plugins for almost every editor out there…
I’ve been using Textpad and then Notepad++ for years and switched to Sublime on the recommendation of a friend.
I was totally dumbfounded when I found out that there is no support for find/replace in macro’s.
Seriously, what’s the point of not supporting something as rudimentary as find/replace in a macro?
Looking back, I see that this has been an issue for ever.
Is there an add-on that I can use to record macros that support find and replace in the mean-time? This is a Big Deal, to me as I use macros’s do some some pretty complex work. I’m just glad I didn’t uninstall Notepad++
Sublime has an alternative “macro” system that supports all built-in features, arbitrarily complex logic, and literally anything your computer can do. The Python API is so powerful and easy to use that I don’t see the point of actual macros. Frankly, I see them as a dubious vestige of TextMate compatibility rather than a valuable feature in their own right, and I wouldn’t expect any significant new development of this obsolete functionality.
If you’ve never written a Sublime plugin, you owe it to yourself to do it at least once. It’s super-easy. I have written a useful complete plugin in less than fifteen minutes start-to-finish in front of an audience. Custom Sublime plugins will change your life.
Not sure which kind of complex work you need to do, but RegReplace is something which might be used to create complex find/replace templates based on regex. Those templates might be called from macros the same way as all available built-in or plugin commands can be.
I didn’t ever feel happy with macros in Notpad++ and I don’t in ST. But @ThomSmith stated the big advantage of ST over Notepad++ already. With some little effort in learning pyhton, you can create much more comprehensive “macros” to help you with your dayly life as you would ever be with Notepad++ (except digging into its C-API and create a C-plugin).
By the way, I didn’t post this (was saved as a draft), strange things supported by macros, like saving bookmarks, should be implemented only after find and replace has been implemented, in my opinion. I’d rather be able to record find and replace using macros rather than save bookmarks! Then again, maybe implementing bookmarks into macros was a simple task, which is why it was done, who knows. I wish Jon would comment on this.
well it was never made possible for the find/replace string to be set from a plugin/macro:
I posted in the previous thread on this subject about a year ago, and have mentioned it in other posts too. A number of people are chiming in with the position that extensions are more powerful than macros, which obviates the need for macros to record things like Find/Replace. I sit firmly on the side of the argument that macros should record everything that makes sense, with a few documented exceptions that should also make sense.
While I agree that extensions are more powerful and can always do the work of a macro - though I feel that Sublime’s API needs some work to really unleash that power - they’re no substitute for macros. The reason is simple: Being programmers, we would rather avoid having to write more programs to achieve sophisticated editing operations wherever possible. For many of us, Python and Sublime’s API are not our primary programming environment so the process can become overly time consuming. The editor is there to save us time and make complex editing operations a breeze. Extensions are useful where we might want to do something complex, repeatedly over time and with necessary logic that might change based on a variety of conditions or variables. Such functionality will often be useful to others. Macros should allow us to record a sequence of operations by doing them, optionally allow refinement by editing the macro’s code, then allow macro playback to be triggered with a keystroke.
The power of a programmer’s editor becomes evident to most when they discover the ability to build complex editing operations out of simple building blocks. Originally a Brief user whose editor of evolved through Emacs, Vim and Crisp for many years (I still use the latter), the ability to record and repeat a series of operations, including and beyond text entry and cursor movements, and play them back with a keystroke or say ‘repeat playback 20 times or until EOF’, is a workflow that can surmount complex editing tasks over large files in record speed. While Sublime’s multi-cursors and multi-selections can get you to the same place in some cases, it often can’t. So I’m left falling back to Crisp as others fall back to Notepad++ etc. to do such things - and that’s a real shame.
Many ask why this is the case. I don’t have insight into Jon’s design choices but I am a programmer, and the reason seems fairly obvious. Jon engineered macros to sequence simple keystroke-based operations like text entry, deletion and cursor movement into atomic language specific operations. Any text editor will need a wealth of these, and a dumb ‘sequencer’ which avoids functional code seems a logical, quick to implement approach. Beyond actual keystrokes, TextCommands are the lowest level operations falling into this category so Jon implemented the facility this way. Adding other types of function adds complexity because they might potentially affect the state of entire buffers, require input etc… So if I’m right the reason is simplicity, justified perhaps by the thinking that multi-cursors/selections would be an alternative workflow to the same ends.
With the time that’s passed it’s become clear that, while useful, multi-cursors/selections are not a panacea for the challenges of complex editing tasks. We need macros that can record and playback everything, which can then be used in extensions or as part of eg. ‘repeat X times or until EOF’.
Addressing Sublime’s key limitations should probably be high on the priority pile moving forward. For me, more powerful macros that record everything, and extensions that can do more by virtue of a richer API should be right at the top of the list.
This seems to me to be the heart of the issue. I respect this position, having once been in it myself. But after using Sublime Text for several years, I feel that it is impossible to take full advantage of it without being willing and able to write new commands. I realize that it can take a while to become accustomed to making a new command a first resort, but for me, the time spent has been well worth it.
I half-agree with your conclusion — I have my own wish list of new API-accessible features. But personally, I would be a little disappointed if a new feature on that list were not implemented because the devs spent their time taking an existing feature that’s already exposed by the API and adding another redundant way to use it.
@qgates Addressing Sublime’s key limitations should probably be high on the priority pile moving forward. For me, more powerful macros that record everything, and extensions that can do more by virtue of a richer API should be right at the top of the list.
I agree with you, but in my opinion, what should be the top of the are the bug fixing:
- Starting with crash bugs. The editor should never crash. At lest for me. The same police apply to my Operating System, it should never crash (blue screen of death). I am very happy to be able to use my OS 180 days continually with no crashes. Means I can trust my computer stability and never loose my work (powered by nobreak, of course, as the light goes out sometimes in that long).
- Performance is also an essence. The editor should be fast. Eclipse, Netbeans, JetBrains Family, etc, too much slow. Hurts to open then, to ask something from them. They just don’t get it. You end up waist more time waiting for they to answer you, then actually working. However they have some more fancy features as organize imports, error checking etc. So sometimes when I am short of time and need just something fast, I keep them both open with Sublime, then when I need to compile, I minimize Sublime and press play on they fancy interface.
- Memory leaks. No memory leaks please. It understandable to use lots of memory when you use lots of features, but keeping eating until 15GB is not nice. But it is understandable. May be you are using so many features you need all that.
I am not saying Sublime Text does all that. Recently Sublime Text seems not to:
- To be crashing. The other day it crashed while I was typing a plain text, but I forgot to let it create a dump file. But since then it is all good.
- Its performance is awesome, it opens fast, closes fast, lots of speed for it. However it is hanging some seconds when I am opening some special syntaxes as the Shell Script, for the first time. Probably it is loading the syntax, etc. When it really bothers, I am going to look into it.
- Does not seem to be leaking memory, the other day it got on 1GB with not files opened, but probably related to how many syntaxes it got loaded and what its packages where saving on memory. For now, this not seems to be bothering.
I use Sublime Text because it has really powerful text features, and it is damn fast. Initially using Eclise & company, but they are too slow, after some years, they got really disgusting. So I started using Notepad++, which is pretty fast. But lacked the fuzzy auto completion and project management. Then I started try everything out there. But the only thing really fast and powerful as Notepad++, was Sublime Text. But even better, it runs on Linux and Windows
@ThomSmith I feel that it is impossible to take full advantage of it without being willing and able to write new commands.
I think, from very far from the other editors, is that Sublime Text allow you to create your own commands. So, yes the full advantage is to write your own commands, therefore it can be wherever you would like it to be. Be your own editor, with your own fingerprint.
@qgates The editor is there to save us time and make complex editing operations a breeze. Extensions are useful where we might want to do something complex, repeatedly over time and with necessary logic that might change based on a variety of conditions or variables. Such functionality will often be useful to others. Macros should allow us to record a sequence of operations by doing them, optionally allow refinement by editing the macro’s code, then allow macro playback to be triggered with a keystroke.
Well, I barely new macros existed on Sublime Text. I’ve using a long time ago this other macro recorder:
May be that third part app can help you. To do mass editions I have been using some packages as:
- https://github.com/ehuss/Sublime-Column-Select
- https://github.com/philippotto/Sublime-MultiEditUtils
And regular expressions with find replace like (\s*)(word1)(\s*)(word2)
-> \1\4\3\2
.
@qgates For many of us, Python and Sublime’s API are not our primary programming environment so the process can become overly time consuming.
Indeed, is pretty time consuming writing new commands. But there are a lot of new commands already written out there. You could inspire and reuse. For now I have been writing some general commands which I can reuse over and over again.
I just ran into this issue today while working with a very large file that was consistently formatted and perfect for macro use. I wasn’t as surprised to find that the search functionality wasn’t supported, but I was very superposed to find that find_under
and find_under_prev
weren’t supported.
I really can’t think of a scenario where the current macros would be helpful.
Before Sublime I used Notepad++ and found myself using macros all the time. After switching to Sublime my macro needs almost disappeared because of multiple cursors and find_under
. But there have been a few times that they were exactly what I needed.
I can say that booting a windows VM, installing notepad++ for the first time in 6 years, and re-learning it’s macro functionality was undoubtedly faster than figuring out plugins.
Personally, I wish that Sublime would integrate Chain of Command (or the equivalent) into the Default package. I’m always skeptical of requests to add new features to core that are available in third-party packages, but I think the case here is very strong.
The legacy TextMate macro system is clunky and missing important features. Users often complain on the forum, and the best recommendation is usually to use Chain of Command. Adopting that as a first-party solution (and adding it to the official documentation) would lead new users to the best solution to a common problem. In addition, package developers could use chains without relying on another package.
This is a plea for the implementation of a much more capable macro functionality. I love Sublime Text, but its biggest short-coming for me is this serious lack of command recording for seemingly anything beyond trivial text manipulation. I appreciate the recommendation for the Chain of Command solution, but I am struggling to get even simple cursor selections and movements to work with it while trying to use it with my example problem below, so I anticipate that its use-cases will be limited.
Veteran editors such as Vi and Emacs have strong macro support that I frequently find myself wishing Sublime had. Yesterday, for example, I was wanting to parse compiler debug output to give me the commands and how long the commands took to execute. The following is sample output (simplified for the example; have hundreds of lines with this structure):
#43 cmd: GET_SETTINGS time In : 515797
#23 time out: 515864
#44 cmd: UPDATE_SETTINGS time In : 515950
#24 time out: 516026
#45 cmd: WRITE_SETTINGS time In : 516112
#25 time out: 516183
To get the following:
GET_SETTINGS 67
UPDATE_SETTINGS 76
WRITE_SETTINGS 71
I am a novice with Python, but have some experience. I managed to write a plug-in to accomplish the above, but it took me at least a couple hours to get it working. Using Emacs I was able to craft a macro in under five minutes (including time to fix a couple mistakes) that does the same parsing. I anticipate that with more experience I might be able to craft a plug-in in around 15 minutes, but this requires Python experience which should not be a prerequisite for text editor users and is still an excessive amount of time for simple one-off tasks where I frequently use macros for such solutions in a minute or five.
Please implement better macro functionality.
Unless your output has a lot more variation, just 30 seconds and multiple cursors will get you what you want. I got the following:
GET_SETTINGS 67
UPDATE_SETTINGS 76
WRITE_SETTINGS 71
Here is how I did it:
- select
cmd:
- press
ctrl+d
to select all instances for multiple cursors - use
home
,ctrl+right/left
andshift
to select the junk - delete it
- move past the part you want using
ctrl+right
, select more and delete - get the two numbers next to each other for each entry via the above method
- type a
-
between the pairs of numbers - open the command palette and run the “Arithmetic” command
- delete the
-
Perhaps your real data is more varied so such an approach wouldn’t work. In general, for basic data massage, I find multiple cursors to be excellent. Beyond that you may want a script in some sort of language so you can tweak it each time as you find bad results, but this is just my opinion.
All that said, I’m sure there are some ways in which macros could be improved.
I’m pleased that this caught your attention. Yes, after spending too much time on this, I did realize that some multi-cursor awesomeness would work and did use the Arithmetic command with success similar to what you did (love that Arithmetic feature!), which took me about the same amount of time as an Emacs macro to get it working. Frequently my macro desires include regex searches for each operation, which I haven’t found to be as easily resolved. Also, my task posted above was to assist a new-to-sublime co-worker who is benefiting from the plug-in I wrote. Yes, they could cut their teeth on Sublime commands, but if macros were more full-featured then they could be passed along for easy reuse at this level as well.
I did use a macro to simplify my double line segments in the example above into one line, but found that the macros wouldn’t use join_lines, which seems like something that should work. I wish the macros would somehow detect and indicate that incompatible commands were used that will not be included in the macro instead of leaving it to failed future results for discovery.
Again, I love Sublime Text and that multi-cursors could save the day on this one. Still, I wish the macro functionality could be expanded to the level of many peer editors - it’s my only reservation with Sublime. Thank you for your time, feedback, and consideration!