8 ms·
Any article that talks about tricks in Sublime Text 2 without mentioning Multiple Cursors is... lacking (no offense to the OP). For anyone that doesn't know it
by edanm 14y ago
Any article that talks about tricks in Sublime Text 2 without mentioning Multiple Cursors is... lacking (no offense to the OP).
For anyone that doesn't know it, Multiple Cursors is the ONE BRILLIANT FEATURE that Sublime Text has. Don't get me wrong, tt's great in many other ways too, but Multiple Cursors is, IMO, a feature that should become part of every friggin' text editor in existence, it's that important. And it only exists in Sublime Text.
It gives you multiple cursors at seperate places in your document. Each one acts completely independently, moving around with your commands. Everything works as expected, including copy-pasting (it will match the copy-pastes up to your cursors).
Most text editors have a column-select mode, except that Multiple Cursors are the same thing on steroids:
1. The selections don't have to be contiguous. So if you have a bunch of:
<div>
<p> Text And more Text</p>
<p> Something </p>
</div>
You can put the cursor only on the <p>s.
2. Since each cursor acts independently, you can do operations that you simply can't do in column mode. For example, place the cursor on each <p>, select to the end of that </p>, and delete the text. This is even if the contents of the </p> are completely different.
3. Multi Cursor gives the same power as macros, but: They're visual! You see all the changes you're making in realtime. Any long-time vim user has probably recorded a macro, tried playing it back, and discovered that it didn't work. Well, with Multi Cursors, you see the cursor and changes in real-time. Make a wrong command? Undo it instantly.
Want an example of another actual use case? I used to have a plugin for Sublime Text that let me split a selection into multiple selections, based on a character. So, let's say I had this code:
foo(int a, char b, char c)
I could select the paramater list, run my shortcut to split by ",", then I'd get a different selection on each paramater. Then, I could simply multi-select three lines below it inside the actual function, paste, and I've got this code:
foo(int a, char b, char c)
int a
char b
char c
A dead-simple editing task I do 300 times a day.
Another example? Let's say I have two "if" blocks in the top of a function:
if (somecondition):
return
if (anothercondition):
return
Now, let's say for a second that I just realized I don't want to return, I want to do some processing, then return. This happens a few times a day for me. I just multi-select both "if"s, hit enter, and add the code. If it's two functions and I need to use the function names, I can even go back, copy the function name, and paste it as part of the processing!!
Phew. If it seems I'm a fanboy for Multiple Cursors, I totally am. It's a brilliant tool that only exists in Sublime Text. I've unfortunately gone back to Vim, and am too far in Vim's world to manage working in Sublime Text, which is why I miss multiple cursors so much!
But I AM working on a Vim plugin that gives Vim Multiple-Cursors. Been working on it for a while, but I think I'm getting near a more-or-less stable version. Hopefully, it will be released soon.
</way-too-long-rant>
- jhdevos 14y agoif (somecondition): return if (anothercondition): return Now, let's say for a second that I just realized I don't want to return, I want to do some processing, then return. This happens a few times a day for me. I just multi-select both "if"s, hit enter, and add the code. Not a great example, because this only leads to code duplication.
- dave1010uk 14y agoI guess you are aware Sublime Text 2 has a Vim mode. As someone who's gone "far in Vim's world", how do you think this compares to regular Vim? I'm starting to learn Vim commands in ST2 but I don't know if "proper" Vim is required to get fully into Vim.
- udp 14y agoOne thing I miss in ST2 Vintage mode is that <> brackets aren't recognized with things like ci< and di<.
- edanm 14y agoI'll be brutally honest. I think it's a great effort, and almost moved back to Sublime Text w Vintage mode several times. And each time, I'll run a command that Vintage mode doesn't have yet, and leave. I'd love it if ST managed to replace vim. I (very unfortunately!) don't see it happening soon. Vim just has so many features and so many plugins. NOTE: Half of my plugins in Vim are only there to make vim behave like a decent, modern editor. In fact, half of my plugins in Vim are there to make it behave more like Sublime Text.
- growt 14y agoI think it's one of the best vim-emulations I've seen so far. It's not 100% but it has things like text-objects (cit, etc.), named buffers and bookmarks (which most of the other emulations miss).
- johncoltrane 14y agoI do V(motion):norm cityour new content<CR>, which does the same as your point 2, very often. But, as you said, multiple cursors is a lot like visual feedback for macros. I miss such a "live" feel sometimes. You got me interested: I'm looking forward for your Vim plugin.