News for hackers. Stuff that matters.
Re:Show HN: Subvim – Vim customized to be like SublimeText by njoh on Saturday April 06, 2013 @01:53PM (#5504348)
The most awesome feature of SublimeText for me is multiple-cursor editing (Ctrl-D on a word). It only bothers me when I can't skip next occurrences easily (It's possible, but it's hard)

It surprises me how users of other major editors don't use multiple cursors in their day to day editing tasks. It'd be awesome if subvim included the best solution vim community has to offer in this regard.

Re:Show HN: Subvim – Vim customized to be like SublimeText by shared4you on Saturday April 06, 2013 @02:53PM (#5504599)
No editor wars intended, but for someone interested: multiple cursors for Emacs: https://github.com/emacsmirror/multiple-cursors

Do watch the video linked to on this page!

Re:Show HN: Subvim – Vim customized to be like SublimeText by efnx on Saturday April 06, 2013 @01:59PM (#5504371)
Vim has block editing mode (ctrl v - select, shift i, write text, esc) and the ability to record macros. With those two features you can do everything multiple cursors does and more!
Re:Show HN: Subvim – Vim customized to be like SublimeText by weaksauce on Saturday April 06, 2013 @02:44PM (#5504565)
I love vim but I don't think that block editing mode does what they want to do quite as well. Do you have an example where they excluded a line or lines from block editing?

an example:

   class="item"
   class="item"
   class="item" 
   class="item"
st2 would be able to select the second and fourth line item and be able to change those to "item odd" without touching the first and the third ones. similarly they could do the same and add even to the other two.

   class="item"
   class="item odd"
   class="item" 
   class="item odd"
this blog post shows it in action:

http://www.sublimetext.com/blog/articles/sublime-text-2-0-re...

Re:Show HN: Subvim – Vim customized to be like SublimeText by efnx on Saturday April 06, 2013 @04:10PM (#5504844)
This would be easily done by recording a macro and replaying it numlines/2-1 times. Possibly if starting on the first line: q,a,j,$,i, odd,esc,j,q,4@a

    qa // start recording into 'a' register
    j // move down
    $ // move last char on line
    i // insert mode
     odd //
    esc // back to command mode
    j // move down
    4@a // replay macro 4 times (if there are 8 more lines)
Re:Show HN: Subvim – Vim customized to be like SublimeText by vitalique on Saturday April 06, 2013 @05:57PM (#5505199)
Yep, using macros are the way to go for a task like this one. I'd use 'A' here to jump into the insert mode at the end of line though (commenting because '$i' part made me realize that I had probably never used '$' for movement at all).
Re:Show HN: Subvim – Vim customized to be like SublimeText by efnx on Sunday April 07, 2013 @02:56PM (#5508204)
That's a good point, '$i' starts inserting just before the last character, whereas with 'A' you'd save the '$i' but have to delete the quote. One cat with many ways to skin it!
Re:Show HN: Subvim – Vim customized to be like SublimeText by Keyneston on Saturday April 06, 2013 @03:07PM (#5504642)
I'm probably being very defensive but I use macros for this.

qa$i odd^[jjq

and then '4@a' to run it on all the lines. In a simple case like this is it a bit more complicated than something like multiword editing but I've used this technique in cases that are far more complex then what from my understanding, multiline editing can handle.

For example I turned a spreadsheet of data into a complicated dhcpd.conf file using a couple macros.

Re:Show HN: Subvim – Vim customized to be like SublimeText by weaksauce on Saturday April 06, 2013 @04:06PM (#5504830)
Oh I agree that macros are a daily use thing for me and I haven't used sublimetext more than a handful of times; I was merely playing devils advocate to see if vim had an interesting feature I was unaware of that I could use in my day to day editing.
Re:Show HN: Subvim – Vim customized to be like SublimeText by njoh on Saturday April 06, 2013 @03:35PM (#5504734)
For more complex tasks like data format conversion, It's probably easier to write some small script and refine a couple of times to resolve possible conversion errors.
Re:Show HN: Subvim – Vim customized to be like SublimeText by translocation on Saturday April 06, 2013 @03:34PM (#5504729)
I might not fully understand the use cases of multiple cursors, but if you were trying to accomplish the same thing (change every other occurrence of "item" to "item odd") in vim, you could do it with 'n' and '.'

    /item        (search for 'item')
    cwitem odd^C (replace with the new text)
    nn.nn.nn.    (next occurrence, next occurrence, repeat last command)
Re:Show HN: Subvim – Vim customized to be like SublimeText by njoh on Saturday April 06, 2013 @03:39PM (#5504748)
For the mentioned task, I prefer to hold control, double click on "item" on lines 1 and 3, press right, and type " odd". Then pressing up, left and type " even".
Re:Show HN: Subvim – Vim customized to be like SublimeText by bosie on Saturday April 06, 2013 @04:10PM (#5504847)
Re:Show HN: Subvim – Vim customized to be like SublimeText by h2s on Saturday April 06, 2013 @07:19PM (#5505435)
I'm a Vim user and this is the only Sublime feature that I think I'd like to see in a future version of core Vim. Another comment called it "syntactic sugar for macros"[1] and that's true. Multicursor functionality allows you to avoid repetition in so many cases that it's worthy of inclusion as a feature in its own right.

[1] https://news.ycombinator.com/item?id=5504507

Re:Show HN: Subvim – Vim customized to be like SublimeText by eddieplan9 on Saturday April 06, 2013 @09:00PM (#5505689)
I think what we already have in vim is even better: just use dot (.) to repeat the last action. So you make some edits in your first cursor position, move to the next cursor position and press dot to repeat the edit.
Re:Show HN: Subvim – Vim customized to be like SublimeText by m_mueller on Saturday April 06, 2013 @09:50PM (#5505803)
No offence, but that's the typical kind of comment coming from someone who's never actually tried multicursor functionality. The thing about multicursor is that it's seamlessly integrated not only with editor commands, but also with commands that create multicursors.

Examples:

- Cmd-Shift-L creates a cursor at the end of every line of the selected area.

- Find all, integrated with Regex, creates multicursors on every match.

- Once you get multicursors, you can still add some manually by holding down Cmd and double clicking at a cursor position.

After you get multicursors, you can then move them around using standard editor commands - that's the real power of this construct, since I'm able to match something much simpler than I actually want to edit (for example end/beginning of line), move to the meat, edit.

Re:Show HN: Subvim – Vim customized to be like SublimeText by m4rkuskk on Saturday April 06, 2013 @01:57PM (#5504361)
Pressing Ctrl-K,D to skip an entry is quite cumbersome, especially if you missed an entry and there is no way of undoing the last selection.
Re:Show HN: Subvim – Vim customized to be like SublimeText by JeanMertz on Saturday April 06, 2013 @03:18PM (#5504676)
Ctrl/Cmd-U is a "soft undo" that undoes your last selection. I agree that Cmd-K,D isn't ideal, but that, combined with Cmd-U works perfectly.
Re:Show HN: Subvim – Vim customized to be like SublimeText by chr1 on Saturday April 06, 2013 @05:03PM (#5505048)
Cloud9 have a nice solution for that, ctrl-alt-left/right to select next previous and same with shift to not keep last added selection. This way you can even skip some words in the middle. I've tried to make a plugin for this, but sublime doesn't keep the order in which ranges were added.
Re:Show HN: Subvim – Vim customized to be like SublimeText by ineedtosleep on Saturday April 06, 2013 @02:03PM (#5504388)
Just tried C-D on my rarely used Sublime Text, but I'm not sure if I'd personally prefer that over something like `:%s/one/two/gc`.
Re:Show HN: Subvim – Vim customized to be like SublimeText by njoh on Saturday April 06, 2013 @02:12PM (#5504433)
I rarely use global find and replace nowadays (just for complex regex replaces). I hold Ctrl-D until all occurrences are selected and type the replacement string (assuming occurrences are low in quantity, which they usually are in most cases).
Re:Show HN: Subvim – Vim customized to be like SublimeText by Already__Taken on Saturday April 06, 2013 @02:37PM (#5504522)
You know crt + H (global find and replace) takes what's highlighted and uses the last thing you looked for it nothing is highlighted.
Re:Show HN: Subvim – Vim customized to be like SublimeText by robin_reala on Saturday April 06, 2013 @04:09PM (#5504839)
Ctrl+cmd+g is cmd+d for all occurrences on the page.
Re:Show HN: Subvim – Vim customized to be like SublimeText by weaksauce on Saturday April 06, 2013 @02:35PM (#5504517)
visual selection replacement is good too.

:'<,'>s/this/to that/g

I think vim does that automatically when you have a selection active and hit :

Re:Show HN: Subvim – Vim customized to be like SublimeText by caioariede on Saturday April 06, 2013 @04:46PM (#5504986)
Note that this will replace over the entirely lines even if it's a blockwise selection.

So you might consider using :'<,'>s/\%Vthis/to that/g

Re:Show HN: Subvim – Vim customized to be like SublimeText by weaksauce on Saturday April 06, 2013 @10:41PM (#5505895)
It might be a setting or something but it definitely doesn't do that on my machine or the linux machine I have in the cloud.

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

select the middle 3 lines and do what I said will give you:

this ipsum dolor sit amet

to that ipsum dolor sit amet

to that ipsum dolor sit amet

to that ipsum dolor sit amet

this ipsum dolor sit amet

Re:Show HN: Subvim – Vim customized to be like SublimeText by MetaCosm on Saturday April 06, 2013 @02:37PM (#5504523)
That sounds like a lot more work...
Re:Show HN: Subvim – Vim customized to be like SublimeText by njoh on Saturday April 06, 2013 @03:23PM (#5504690)
No it's not! Plus, you'd get to see the replacement targets while you're holding the keys, so you'd be more confident about the final result.

Just give Ctrl-D a try for a couple of days.. It's a total different user experience compared to the traditional find/replace method.

Re:Show HN: Subvim – Vim customized to be like SublimeText by dmatlack on Saturday April 06, 2013 @03:45PM (#5504761)
Do you mean it's a lot of work to type in that prefix? Because vim automatically inserts it for you when you enter command mode while something is visually selected. A making a visual selection is very quick and easy.
Re:Show HN: Subvim – Vim customized to be like SublimeText by Derbasti on Saturday April 06, 2013 @07:43PM (#5505498)
I would not say it's essential, but multiple cursors is certainly one of the features I use quite frequently in Emacs. In many occasions, it is more useful than plain search and replace, though even that is kind of super charged in Emacs to bein with.
Re:Show HN: Subvim – Vim customized to be like SublimeText by farslan on Saturday April 06, 2013 @07:03PM (#5505388)
OP here. There are some plugins but I didn't research it. But here is one that I think do it (and if it's good I'll integrate it): https://github.com/paradigm/vim-multicursor
Re:Show HN: Subvim – Vim customized to be like SublimeText by maxmcd on Saturday April 06, 2013 @05:16PM (#5505093)
Command + K skips the most recently highlighted occurrence. Usually works for me.
Re:Show HN: Subvim – Vim customized to be like SublimeText by daGrevis on Saturday April 06, 2013 @02:33PM (#5504507)
Multiple-cursors are just a syntactic sugar for macros.

s/syntactic/visual/

Re:Show HN: Subvim – Vim customized to be like SublimeText by roryokane on Saturday April 06, 2013 @04:52PM (#5505018)
Multiple cursors simulate not just macros, but also setting lots of marks and iterating the macros through them. It’s relatively easy to write an equivalent macro if you’re just placing a cursor every three lines or at every occurence of some string; you can have the macro move three lines down when it’s done, or search for the next occurence of some regex. But if you’re actually clicking on places in the code that only a human can identify need changing, then it’s much harder to write an equivalent macro.
Re:Show HN: Subvim – Vim customized to be like SublimeText by jQueryIsAwesome on Saturday April 06, 2013 @07:10PM (#5505413)
Is awesome but it needs some work, it would be _really_ nice if it were syntax aware, so if you start Ctrl+D in a variable it should only select where is being used as a variable and not other things (regex, strings, etc) or at least a boolean option to enable this behavior.