

Show HN: vim-multiple-cursors - True Sublime Text style multiple selection - tma
https://github.com/terryma/vim-multiple-cursors

======
codemac
If there is one thing I love about vim, sublime, light table, etc.. is it
gives emacs fans new things to implement in elisp!

But seriously, I love the work that has been going into all these different
text editors. It seems to be net benefit for everyone. Multiple cursors are
like a visual kbd-macro-edit..

Obligatory emacs equivalent source:

\- <https://github.com/magnars/multiple-cursors.el> \-
<http://emacsrocks.com/e13.html>

By the ever awesome Magnar Sveen

~~~
tma
I should probably put a reference to him on the project page, as watching his
video recently was a big push towards making me implement this in Vim. His
expand-region plugin also inspired me to create vim-expand-region. I wonder
what I'll 'copy' next. :)

~~~
gaving
Thanks for mentioning (& developing) this, vim-expand-region is awesome.

~~~
tma
Thanks! expand-region and multiple-cursors run in the same vein in that it
takes some functionality Vim already offers, and makes them a little easier to
use to the average user. I'm a pretty new and definitely average Vim user
myself, and remembering just 2 keystrokes to select some region of text is
definitely much easier on my brain muscle than having to remember the dozen of
text objects offered by Vim as well as other plugins. Maybe one day all of
them will be burnt into my muscle memory, but that simply isn't the case today
and expand-region helps me remain productive while learning. :)

------
adimitrov
Issues:

> * Multi key commands like ciw do not work at the moment

> * Single key commands that do not terminate properly cause unexpected
> behavior

> * Undo behavior is unpredictable

> * Performance in terminal vim degrades significantly with more cursors

There are some more than just these. I really wish Vim were easier to hack.
The cursor and drawing models are terribly rigid in Vim, so this plugin
probably has to resort to some awful hackery to achieve what it does. :-(

That said, good work, but I'll hold off on trying it out, for now. I'd like at
least undo to be fixed before I can use it frustration-free in my _production_
-environment, i.e. producing actual code.

I really hope you continue your work, because I'd love to see multi-cursor
functionality implemented in Vim!

~~~
tma
Thanks for the feedback. I'd love for any issues you've seen to be reported so
I can get on fixing them. I finally got the plugin to a usable state today and
decided to release it early to get feedback, knowing that there're a ton of
bugs and missing features. And you're right, figuring out ways to hack around
Vim's peculiar ways wasn't an easy task by any means.

~~~
adimitrov
Absolutely fine, I love that you're doing this! I'll give it a run tonight
when I have some free time, maybe even look into the undo-stuff, which I think
is most important to me.

------
edanm
For everyone here writing that they don't see a need for this because vim has
macros/regexp's:

Please, please, try it out. I'm telling you, this is leaps and bounds above
macros/regexp's for most use cases. It's the difference between a _visual_ way
to make changes, and a "disconnected" way in which you write commands and hope
they work.

Seriously, I consider Multiple Cursors one of the greatest advances in text
editing, and everyone who doesn't even bother to try it is just being silly.

~~~
_delirium
I've been trying it, and do find it nice for small things, but a bit tedious
for bigger things. Taking one of the examples in the animated GIF on the
linked page, if you want to split a line on commas, with multiple cursors you
have to select every single comma to 'initialize' the cursors. If the line has
3 fields, this is easier than using the regex, but if it has 10, then I find
it a lot easier to just regex-split rather than spawning 10 cursors. I think I
find 3 or 4 cursors nice, but past that prefer batch-style commands to
manually managing a big set of cursors.

~~~
losvedir
> _with multiple cursors you have to select every single comma to 'initialize'
> the cursors._

I hear this. Hopefully, the author will be able to implement what Sublime has:
a find all field (which accepts regular expressions), and results in multiple
cursors on all the matches.

I do this all the time in Sublime and it's so natural:

Cmd+F, /regex/, opt+Enter, [replace, or commands or whatever]

It's just as fast as your usual find and replace or quick macro, except that
you have instant feedback, are able to undo, jump around by word, or (with
vim-mode), use t or f to find a character, ci", etc.

Selecting a match one case at a time is great, though, when you need to skip
some matches. Say you have `old_var`, `old_var2`, and `old_var3`. Just start
at the top of the function, and match, match, skip, match, skip, [type and
replace]. Sure, you could do a regex on old_var[^\d], but depending on what
you're matching and what you're skipping it sometimes is just not worth
puzzling out the right regex.

------
ParadigmComplex
I threw my own attempt at this on HN a ways back, but it didn't get any
traction: <https://news.ycombinator.com/item?id=4906343>

Mine supports things like multi-key commands and has predictable (if not
entirely desirable) undo behavior, but it has issues in its own right. I
figure we may both learn a thing or two from each other's attempts.

Vim really does need this feature to get some mindshare back from ST2, and I'd
love to see this well-implemented, even if its by someone else.

------
rane
The rendering of multiple cursors is really buggy in tmux + vim, to the extent
that it's hard to tell what has been selected.

I have used this command for the purposes of changing a variable name. It
could be better but gets the job done most of the time.

> :.,$s/\<<C-r><C-w>\>//gc<Left><Left><Left>

Short demo: <http://cl.ly/image/403j153F3u1h>

~~~
susi22
I do this: *Ncw (then change the variable name) Then just n.n.n.n. until
things are replaced.

------
grn
I must admit that I see little value in it given great capabilities that Vim
already has. The three example edits can be made using regular expressions and
macros.

~~~
lttlrck
Surely it's most obvious value is it's 100% interactive.

------
farslan
That's awesome tma. Thank you for hacking on this. I'll plan to include this
into subvim (ST2 like Vim) :)

~~~
flipcoder
subvim? :O awesome idea (although I wouldn't use it since I'm so used to my
vim setup, but I could see lots of people using it)

I'm linking it here so people can find it: <https://github.com/fatih/subvim>

------
cab9485
Thank you for posting this. I didn't even read the article but my mind is a
black hole when it comes to remembering names and I have been forgetting
Sublime for a while now.

------
nkuttler
It looks to me like using a regex is more practical, something like

:10,20s/poorly_named_var/nice_var/g

~~~
joesb
If you do nothing more than a scoped search-and-replace then regexp may be
more practical. But if the edit action also involve moving cursors around
after selection, or when some match should be skipped then it takes less
effort to use multiple cursors to edit than trying to comes up with regexp and
edit command that accomplished what you need.

------
alan-saul
Looks great, I was actually about to start working on an identical project
today!

------
pw7
Looks great tma! Will give this a spin as soon as I can.

------
gokce
I don't need to get jealous of sublime anymore..

------
ashleyblackmore
Thank you Terry, this is great

------
neduma
Awesome. Gonna try it.

------
aeon10
what is the font used in the example gifs

------
jQueryIsAwesome
Slightly related: If you are using ST2 I recommend the "Clipboard Manager"
plugin to have multiple clipboards, it gets anything that is copied inside ST2
or any other software, it works with multiple cursors which is really handy.

~~~
jjjjjosh
I just tested this with native copy-paste, and - at least on OSX - as long as
whatever you're pasting has the same number of lines as you have cursors,
you'll get that same line-to-cursor mapping.

That being said, let me also recommend my favorite clipboard history tool,
Jumpcut (<http://jumpcut.sourceforge.net/>).

