Hacker News new | ask | show | jobs
by weaksauce 4829 days ago
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...

4 comments

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)
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).
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!
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.

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.
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.
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)
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".