Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you please give an example of that? You've got my curiosity piqued :)

Btw, another place this can't be used is across multiple files, at least the way ST does it.



Sample

    def qux(bar, baz, qux)
        pass

    def quuux(grim, gram, grom)
        pass

    def quuuuuux(hip, hop, zoom)
        pass
Delete second argument (of 3+ arg functions):

    /def<CR> # search
    qd       # record as 'd'
    2f,dF,n  # find second arg
    q        # done recording
   
    @d       # again (or n to skip)
Example intentionally simplified/convoluted. I'm doing stuff like this on the spot routinely, and there's no way multiple cursors could do this because I apply verbs to text objects that ST has (unless I'm missing something) no way of knowing about in a visual paradigm without resorting to guessing what I mean.

What would be killer is mixing both, i.e visually selecting where to apply a vim macro.


Actually, this is a perfect example of using Multiple Cursors to get the job done more easily.

I'd select all three "def"s simultaneously, then move by word three/four times using ctrl+right, or plain old "w" if using ST's vim mode. When I'm on the second param, I'll delete forward to the next ",". I could also just ctrl+right my way until the next word, which would be the same.

Just to recap the keys I'd press:

/def (select first def) ctrl+d * 2 (select using multi-cursors the next two defs ctrl+right * 4 (to get to the second param) ctrl+shift+right (to select the entire second param) delete

And if I mess up at any point, I instantly see it. If I did something that only works for the first case but not the others, I see it immediately.

Note: Using vintage mode, Sublime Text has vim shortcuts. Without it, Multiple Cursors still rock, but are missing a LOT of their power (exactly because of situations like this).

In fact, in Sublime Text 1, for which vim mode didn't exist, I actually implemented a plugin to emulate the "f" and "t" movements because they were so good.


> When I'm on the second param, I'll delete forward to the next ","

you can't do that, else you'll delete not enough ('gra') or too much ('baz,')

> ctrl+shift+right

It fails the moment one of the second arguments has a space or a dash. e.g default value:

    def qux(bar, baz = {}, qux)
or in some languages (CSS, HTML, LISP)

    <div class="foo bar-baz quux" data-behavior>
The interesting reason is why it fails: you say you want to delete 'to the next ","' but do word movement with w or ctrl+arrows. Indeed this is solved by Vintage mode, but I unfortunately found it too inconsistent with vim, and lacking a few critical features (e.g vim-surround and indent-object) for me.

Also, multiple cursors rock anyway, but if I want to apply them to a number of elements responding to a criteria and decide on a case by case basis if I want to apply then it does not work. Also it does not work when there's no code locality (i.e affected code is not visible in the same view, or spread around multiple files). The major difference with macros is that they're repeatable, while multiple cursors do the same thing at once, and once.

Also, when one vim user uses f/t too often, one should look into an object describing what he wants to really do (here [0]).

[0] http://www.vim.org/scripts/script.php?script_id=2699

I hope Sublime Text has or introduces at some point the same extendable concept of text objects as in vim.

Don't get me wrong, I'm not saying anything of this is bad per se, just that there's room for improvement.


How do you make multiple cursors that are at the exact locations you need?

That's something that a macro is useful for. His macro is less useful because for some reason he did his search outside of the macro. Maybe the search is not for "def", but for "def prefix", so ctrl+d is not applicable to form the multiple cursors.

It could be nice if you could record your movements to form the "next" cursor and immediately see all future generated cursors given that movement (similarly to the "recursive draw" web app). Then you could perhaps truncate the infinite list of cursors at some finite point somehow, and then operate your multiple cursor operations.


"How do you make multiple cursors that are at the exact locations you need?"

There are a few simple tricks.

In this case, I hit "ctrl-d", which does the following:

1. If nothing is selected, it will select the word the cursor is on.

2. If something is selected, it will select the next match of this word, using another cursor.

In other words, I'll put my cursor on "def", hit ctrl-d, and "def" will be selected. Hit ctrl-d again, and the next "def" will be selected. Etc. Technically, in Sublime Text, every search makes a multiple cursor. I could hit alt-f3 (IIRC) to select all matches of "def", and they'd all be multi-selected.

But like I said, in this case it's really easy.

There are more advanced tricks - what if the word "def" appears inside the text? Well, you can select not only the def, but also the whitespace before the def, and it will selected the next "def" which is at that exact indentation. And like I mentioned in another comment, I even wrote a plugin to make multi-selections more easily, by splitting on a certain character. So that a list like this: (int a, int b, char c) can easily be split into 3 selections, around the comma.


Now that's the kind of thing I wish I would see in a "ST tricks" blog post.


Sounds great, hopefully someone ported this to emacs :-)


If you put the "/def<CR>" part in the macro too, then you can re-execute it multiple times.

I think it's actually useful, not simplified/convoluted..




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: