7 ms·
I keep trying to get into vim, but I just really enjoy multi-cursor editing in Sublime Text. The example in the article of changing multiple lines using '.' to
by ghayes 5y ago
I keep trying to get into vim, but I just really enjoy multi-cursor editing in Sublime Text. The example in the article of changing multiple lines using '.' to repeat is the same as selecting the three lines in Sublime Text, entering multi-line edit mode, and then typing the change once. The same applies for replacing a single word (e.g. with Cmd+D) and/or regex replacements. Basically, I have a really easy time avoiding any repetitive commands in my normal day, so I wonder what the real advantage of vim would be for my use case. Or maybe I just don't know what I haven't yet learned...
- saboot 5y agoIt's been a while since I've used vim, but I definitely recall doing multiline editing as you describe in vim. There is a visual-block mode that does multiple cursor manipulation
- sva_ 5y agoYou can select multiple lines in vim using ctrl-v, then do some action on all lines like inserting by shift-i, or whatever you want to do with the lines. Replacement with regex is also trivial.
- deleted 5y ago[deleted]
- stevebmark 5y agoAs a power Vim user, I can attest that multiple cursors do at least 75% of what I want to do in Vim, and multiple cursors are better and faster.
- h0l0cube 5y agoHow about macros? I find i use them on at least a daily basis
- cercatrova 5y agoWhat kinds of macros do you use?
- h0l0cube 5y agoYou can build a macro on the fly to do some transformation for, say, a line of text, or even a function, and just repeat those manipulations. Usually they are crude combinations of vim inputs that work well enough for the situation at hand. Obviously it's not a replacement for IDE refactoring, but if you're using a vim emulator, you can do both
- beej71 5y agoOne transform I've done a few times is something where you have a list like this: foo bar baz And you need each line transformed into: [Foo](https://example.com/foo.html https://example.com/foo.html) Or something like that. Macros make short work of it.
- WithinReason 5y agoMultiple cursors as well.
- beej71 5y agoMy multiple cursor-fu isn't good enough to know how to do that with words of different lengths. I should get more into it.
- vicda 5y agoMacros and replaying my last command at a new location are the biggest thing I miss from vim. With regex replace groups you can generally get close enough to the desired productivity though. (Personally, I find vim's multiselect cumbersome to use compared to sublime/vscode's.)
- rgoulter 5y agoVim's keymap has a wide variety of 'text objects'. Reiterating point 3 from the article: e.g. if the cursor is at | in: printf("Hello |World\n"); With vim, you could manipulate the text in different ways by using different motions, e.g.: `db` would give `printf("World\n");` (b for backwards), `de` would give `printf("Hello \n");` (e for end-of-word), `di"` would give `printf("");` (inside `"`), `di(` would give `printf();` (inside `(`), or instead of deleting, some actions could be useful, like changing to uppercase: e.g. `gUi"` would give `printf("HELLO WORLD\n");`
- szszrk 5y agoDidn't realize I could do `di"`... that's so neat. I always at least whip through such articles about vim as there may be something I don't use daily, but could. There always is such a thing. I love to use all the zero-configuration things that are already present in Vi/Vim at work. IDE's are cool for devs or people who do everything from a stable workstation. I rarely have such comfort, jumping from one server to another, from one image to another. And Vi or Vim are always there. Thanks for all those hints.
- WithinReason 5y agoFor VSCode users: ctrl+backspace: `printf("World\n");` ctrl+delete: `printf("Hello \n");` alt+shift+right, alt+shift+right, delete: `printf();`
- totony 5y agoOr install the vim emulator plugin. It's not perfect but it does a lot
- wruza 5y ago. is more general as it repeats any editing action, not only insert-at-cursor. I keep trying to get into vim Speaking out of my 20 years experience, you probably shouldn’t. You’ll find vim a little behind sublime/vscode in some parts and will keep trying to get out of it, unsuccessfully. I came to conclusion that I wish all of the editors (vim included) separated editing from their operation and made it modular (vim-like extensions are limited to a subset of it and are really worst of all these worlds, cause only half of your habits work and none of your scripts/addons do).
- h0l0cube 5y agoAlmost every modern editor has some form of vim emulator, so you can have the best of both worlds
- wruza 5y agoThese don’t work for me because I made a slip and added too much vim-specifics to my editing/workflow habits. Vim emulators only work for those who have 3-5 years of non-active exploration experience. Once you commit to plugins, buffer/window-related actions, scripts, hooks, heavy vimfiles setup, etc, the way back is as hard. Edit: please don’t downvote the parent commenter, it’s a non-obvious knowledge and it doesn’t apply to everyone.
- h0l0cube 5y agoYeah okay, I understand emulation is a subset, but surely a modern IDE takes care of most of the productivity gains you get from customization and adds a few more, like the context/AST-aware refactoring you find in Jetbrains IDEs Edit: I spent a long time trying to make Vim more IDE-like, but found it was more productive to make my various IDEs more Vim-like, but I concede that might not be suitable for everyone
- wruza 5y agoYeah, I’m also leaning to just learn the heck out of vscode internals and tune it to my own needs maybe via custom plugins, instead of running behind the train. Sometimes investments just stop returning, and you have to make bold moves want it or not.
- asiachick 5y agoAFAICT multi-cursor mode is not nearly as useful as vim (or keyboard macros in most editors). I don't know SublimeText but I do know, functionality of multi-cursors is often limited. For example, say I want to go to all functions calls foo(aa, bb, c); foo(d, ggg, hh); foo(iiii, i, jjjj); I want to do something to the 2nd argument on each line. add a fn(prevContents). So I search for "foo(" and then pick "put a cursor on every match". Then how do get to the first comma and the select to the second comma on each line? This is easy with vim, easy with keyboard macros, not easy with multiple cursors (that I know of). For example as soon as I press "find" so I can search for the comma I lose multiple cursors. Maybe there's a special "Search with multiple cursors" command but if so that just highlights the issue, you shouldn't need special commands, you should be able to combine existing commands. vim and keyboard macros make that easy.
- dracyr 5y agoNow, I use vim mode in Sublime, so I have already "seen the light" so to say. But that situation is probably one I'd actually be able to solve faster with multiple cursors. What I'd do is this: Put the cursor on one of the calls, then use ctrl-d to put a new cursor at all the matches. Then use ctrl-right-arrow to move by word until the second comma, combine that with shift to select the argument and edit all of them with visual feedback to my heart's content. In reality, depending on the complexity of the text, after creating all the cursors, I'd probably use the vim movements to get them to where I need though.
- LegionMammal978 5y agoFor things like that, I usually make use of the C-Left and C-Right combinations to get to the same place on every line; after all, if two lines are similar enough for me to do the same thing to all of them, they very often have the same sequence of words. (Sometimes there can be issues, e.g., if one line has an extra index.) For reference, I tried your particular example, and the keystrokes look something like: C-f, "foo\(" [open a Find dialog] C-Enter: [foo(]XX, YY, ZZ); [Find All shortcut] Right: foo(|XX, YY, ZZ); [move to the right side of the match] C-Right: foo(XX|, YY, ZZ); C-Right: foo(XX,| YY, ZZ); C-Right: foo(XX, YY|, ZZ); C-S-Left: foo(XX, [YY], ZZ); [select leftward] I suppose that it's not quite as ergonomic as Vim keybindings, but it's definitely less of a departure from the usual OS text boxes.
- ryannevius 5y agoThere are endless patterns for using Vim. Here are a few which I use frequently instead of multi-cursors: https://asciinema.org/a/v7pOP4tqxPOPUu1HwbixmuUnS https://asciinema.org/a/v7pOP4tqxPOPUu1HwbixmuUnS I switched to Vim from Sublime Text years ago, and honestly multiple cursors and the live search and replace (especially across multiple files) were both missed until I learned how to do them in Vim just as easily. Vim is a multi-year investment, and isn't worth it for most people.
- marklgr 5y agoMultiple-cursor editing is a nice and cool feature, and for what it's worth there are some vim plugins to get it in vim, but let's see the alternative: - multiple-cursor: select non-contiguous pieces of text, then edit them all at once. - vim macro/repeat: edit a piece of text, and repeat on similar occurrences. The vim "way" could be, `/;$` to select the trailing semi-colon, then `cgn` to edit it (enter the curly block once in insert mode, then exit with `<Esc>`), and now you can repeat on the next trailing semi-colon simply by hitting `.` (dot). So, instead of first looping on the occurrences to get multiple cursors, then do the editing, you first do the editing on an occurrence, and you loop on the editing. There is admittedly less of a "wow" factor, but I don't think it is any less powerful. (edited for formatting).
- edanm 5y agoIt is way harder to use macros than to do multiple-cursor editing, especially for the kind of fast changes that happen 10 times a day. The difference is between seeing interactively exactly what you are doing and where something is going wrong (with multiple cursors), vs. recording a macro, replaying it, realizing you forgot to do something like use the correct keybinding, rerecording, etc. I say this as a huge vim advocate, who used vim exclusively for 8 years before switching to emacs and lately to vscode. Vim gets a lot of things right, and there's no comparison to using vim-style editing. But multiple-cursor editing is a killer feature that really does improve your workflow a lot of the time. Luckily most editors have some version of it now, though often not as good as the original and doesn't always play nicely with the various vim modes.
- sva_ 5y agoIf you insist, you may have a look at https://github.com/mg979/vim-visual-multi https://github.com/mg979/vim-visual-multi It implements multi cursors in vim and combines it with vim movements etc.
- edanm 5y agoYeah I used it (or something similar) when I was actively using vim. It wasn't as good as a proper IDE but was fairly good for a variety of use cases. (I actually tried to implement my own multi-cursor plugin in vim, and got a decent amount of the way there before realizing my fundamental approach probably wouldn't work.)
- alexvoda 5y agoFor the same reason I find the grammar of Kakoune a lot easier to understand. It is similarly subject first instead of predicate first. I wish there was a NeoKak that would integrate with other environments like VS Code the way NeoVim does.