5 ms·
I switched to vim a year ago, and I fucking love it. The one thing I miss from ST2 is column editing/multiple cursors. Column editing fulfills the same kind of
by notJim 14y ago
I switched to vim a year ago, and I fucking love it. The one thing I miss from ST2 is column editing/multiple cursors. Column editing fulfills the same kind of need as basic usage of vim macros, I think (i.e., applying some kind of sequence of edits to multiple rows), but it's visual and you get instant feedback (across all rows), which makes it easier and something you can sort of feel out iteratively.
For example, supposed I have a row like (making up these names as I go, and suppose the list is longer):
Controller_Section
House_Model
Person_To_Category_Selector
and I want to insert after the first underscore the word class, so I'd get Controller_Class_Section and so on (this is a contrived example, but one has to do these kinds of things sometimes.)
In vim, I think I'd record a macro, but I'd probably forget some parts (like moving to the next line at the end) and have to undo and whatnot (could use a regex too, but that's a bit harder--I'm practicing recently to be able to do it more effortlessly.)
In ST2, what you do first is create a cursor at the beginning of each row (option + down arrow on OS X.) Then you move ahead one word (Opt + Right arrow on OS X.) Now the cursor is right before the underscore, even though the underscore is in a different position on each row. You can see that it's in the right place on each row, so it's hard to make a mistake, and if you need to do something more complicated, that remains true. Then, you just type _Class, and it types live on each row, once again making it so you get instant feedback, and it's hard to make a mistake.
That to me is the biggest actual advantage of ST2 over VIM, but there are other reason to not switch, like vim's steeper learning curve (when most of us are already busy, and learning other stuff at the same time), and the fact that some people prefer the mouse, which behaves strangely in vim.
- groovy2shoes 14y agoMultiple cursors sound cool! In vim, you can do something more limited by using visual block mode (C-v) to insert on multiple lines, but you're restricted to insertion on the same column. The perhaps the closest thing I can think of for your example would be this (starting in normal mode with the cursor at the beginning of your list): f_i_Class<Esc>+;.+;. ("Move forward to the next '_', enter insert mode, insert '_Class', leave insert mode, move down one line to the first non-blank character, repeat the forward motion, repeat the insertion, repeat forward motion, repeat insertion." Vim does have word motions, but it includes underscores as parts of words.) Edit - formatting and a clarification that it's the closest I can think of (I'm doubtful it's the closest you can get).
- notJim 14y agoYeah, I'd record that as a macro and replay it line by line I think.
- LiveTheDream 14y agoMacros are the way I solve this as well. A little practice, and you won't even notice the difference. Just hit `Esc j` before ending the macro recording and moving down a line is no longer a problem :)
- irahul 14y agoRather than replaying it line by line, you can play it over a range. If you do this in your vimrc: vnoremap @q :normal @q<CR> You can record the macro in q register, select the visual range, and then do @q to run it over the range. The advantage of doing it thus is you don't have to run the macro manually on every line, and you can undo all change with one u. Also, normal takes ranges(and not just visual ranges). If you want to run the macro recorded in q over lines 15,49, you can do: :15,49normal @q<CR> I use the same trick for repeating commands over a range too. vnoremap . normal .<CR> As usual, it doesn't have to be visual range. But I mostly use visual ranges, and so I have defined shortcuts for visual ranges.
- clscott 14y agoYou wouldn't do the following? :% s/_/_Class_/ Explained: On each line replace the first '_' with '_Class_'
- notJim 14y agoYeah, that's totally what you'd do, in either editor. But my broader point is that there are situations where the immediate feedback and interactivity of using multiple cursors is valuable.
- johncoltrane 14y agoI've tried to like it and believe that instant feedback is actually useful but no. I couldn't.
- maxnik 14y agoI usually use "repeat last change" (. key in normal mode by default) command in vim without a macro for the tasks like that. http://vim.wikia.com/wiki/Repeat_last_change http://vim.wikia.com/wiki/Repeat_last_change To do the task you mentioned in vim I would move the cursor to the first letter of the word Section in the first line. Then I'd insert "Class_" and go back to normal mode. After that I'd move the cursor to the first letter in the word Model in the second line. And then I'd press the dot key and do the same with the other lines in supposedly longer list.
- hilko 14y agoI do that with Sublime Text 2 using the vim plugin (vintage). I would've never switched from vim if not for this plugin. Now I have (most) of the best of both worlds.
- rahoulb 14y agoI have to say vintage did my head in. I guess to me, vim requires a different mindset to a "modern" editor, and vintage mixed the two. Now I seem to spend a few months with vim as my primary editor, get tired of it, switch to ST2 for a few months and then switch back.
- irahul 14y ago> And then I'd press the dot key and do the same with the other lines in supposedly longer list. I am posting this again(posted above about running a macro on a range), but I guess lot of people don't know about this.You need not manually press . on every line. You can run . operator on a range. Do a visual select and then :'<,'>normal .<CR> The range('<,'>) is inserted automatically when : is pressed from visual mode. So it boils down to visual mode, select, :normal . <CR> You can have any ranges you want. :15,49normal .<CR> I have a shortcut for visual range defined in my vimrc vnoremap . :normal . <CR>
- johncoltrane 14y agoUse <C-v> for column editing. Your example is not a candidate for a macro, a simple substitution is enough: V2j to visually select the lines :s/_/_Class_<cr> a range corresponding to the visual selection '<,'> is inserted automatically before the s If you are comfortable with ranges, the operation can be done in one go: :.,+2s/_/_Class_<cr> Also there are already a few plugin authors exploring the multiple cursors idea, however gimmicky it is.