8 ms·
Show HN: vim-multiple-cursors - True Sublime Text style multiple selection
- codemac 13y agoIf 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 https://github.com/magnars/multiple-cursors.el - http://emacsrocks.com/e13.html http://emacsrocks.com/e13.html By the ever awesome Magnar Sveen
- sjm 13y agoI love Magnar's multiple cursors. I end up using it at least a few times a day, and it always saves me a ton of time.
- tma 13y agoI 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 13y agoThanks for mentioning (& developing) this, vim-expand-region is awesome.
- tma 13y agoThanks! 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. :)
- deleted 13y ago[deleted]
- swah 13y agoThat was a great video - I just wish he'd used an app to show all keys he's pressing (since there's something to pickup from advanced emacs' users). Used Emacs from a few years and I don't remember any more how to do all those things!
- jQueryIsAwesome 13y agoSlightly 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 13y agoI 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/ http://jumpcut.sourceforge.net/).
- neduma 13y agoAwesome. Gonna try it.
- adimitrov 13y agoIssues: > * 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 13y agoThanks 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 13y agoAbsolutely 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.
- nkuttler 13y agoIt looks to me like using a regex is more practical, something like :10,20s/poorly_named_var/nice_var/g
- joesb 13y agoIf 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.
- deckiedan 13y agoI wish vim had a visual regex multi-replace tool, like the visual search tool. So matches would select as you typed, and changes would update in real time too...
- grn 13y agoI 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 13y agoSurely it's most obvious value is it's 100% interactive.
- pw7 13y agoLooks great tma! Will give this a spin as soon as I can.
- ashleyblackmore 13y agoThank you Terry, this is great
- aeon10 13y agowhat is the font used in the example gifs
- alan-saul 13y agoLooks great, I was actually about to start working on an identical project today!
- edanm 13y agoFor 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 13y agoI'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 13y ago> 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.
- dhruvmittal 13y ago
- gokce 13y agoI don't need to get jealous of sublime anymore..
- cab9485 13y agoThank 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.
- farslan 13y agoThat's awesome tma. Thank you for hacking on this. I'll plan to include this into subvim (ST2 like Vim) :)
- flipcoder 13y agosubvim? :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 https://github.com/fatih/subvim
- lttlrck 13y agoI am looking forward to trying subvim this on Linux.
- tma 13y agoThanks! I was planning on pinging you to check it out, but it looks like it found its way to you already. Also thanks for jumping in and finding problems already!
- rane 13y agoThe 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 http://cl.ly/image/403j153F3u1h
- susi22 13y agoI do this: *Ncw (then change the variable name) Then just n.n.n.n. until things are replaced.
- ParadigmComplex 13y agoI 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 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.