Anyone have some better examples of things you can do with Vim that make it worth learning over a GUI-based editor like Atom?
Anyone have some better examples of things you can do with Vim that make it worth learning over a GUI-based editor like Atom?
ci( - Change inside parentheses ci" ci' ci}
If your cursor is anywhere inside a set of parentheses, (if, while, for, function call, aka this happens a lot) and you need to change everything inside the parentheses, just type ci( and it deletes everything inside the parens and puts you in insert mode so you can start typing. Guess what ci" and ci' do? How often do you need to rewrite a string? This is huge.
dd - Delete line
Deletes the whole line with a quick double tap of a home row key. So much faster than highlighting the whole line with the mouse and hitting backspace twice, or hitting home, shift+ctrl end, backspace backspace. Want to delete 3 lines? 3dd.
A
Move to the end of the current line and start typing. Super simple and nice to have.
w
Move to the beginning of the next word. Way more ergonomic than ctrl+right arrow.
yyp
Copy the current line and paste it below the current line. Super simple, super fast.
Those are the commands that make Vim matter to me. Once you put in the time to make them muscle memory, you'll never look back. There are of course tons of other commands, but I can say that those are the ones that changed how editing text feels to me.
1. The main benefit of vim or any editor is not some fancy feature like macros or visual block editing. Although vim has those and they are great, they only become useful in about 20% of situations. When coding, you spend much more time reading code than writing it. That's why vim has you in Normal mode most of the time, where you can't type at all, and the whole keyboard becomes a tool for navigating. Reaching for the mouse incurs an unconscious mental cost that affects the way you read and write code. Editor ergonomics do impact your codebase.
2. Vim's ratio of power to learning difficulty is the best out there, because once you learn one word of vim's "language", you can combine it with every other word you know and it will behave how you expect.
3. I never try to convince people to switch to the actual vim editor because it requires a ton of customization just to be usable, and overall it's not that great. It's filled with cruft and weird things like a custom scripting language. The only important part is the key bindings, and you can get those in any modern editor. I use about 4 different editors and IDEs on 3 platforms on a daily basis. I never had to learn all their crappy keyboard shortcuts because they all have vim key bindings.
The key observation behind its design is that programmers and sysadmins spend much more time editing than entering new text, and therefore it is asinine that 40 of the keys on the keyboard are permanently dedicated to typing out literals when there are very obvious editing operations that give you a lot more leverage.
You don't have to give up Atom, you can use Vim bindings in atom. Most editors support it to some extent via plugins.
I use vim bindings in Visual Studio, and I combine it with Resharper, and that is insanely awesome. I started writing a guide to it ( https://github.com/keithn/vsvimguide ) but it needs a bunch of work, I keep changing my mind about what the best starting bindings are to get the best blend of VS + R# and Vim ( I mainly fully embrace the Vim way, but I think thats too much when starting, it's best to start with the core Vim moving/editing and then learn to customize). But I digress, the "Changing Text" section has a number of combos that people often find a selling point of using Vim.
For example, the `d` key begins the `delete` action, the `i` key means `inner` (or `current`) and `w` means `word`. From that, you can deduce that `diw` deletes the current word.
I figured that command out myself, among many other ones, and that only works because of the composable nature of Vim's modal editing.
Vim's macro system is also rather amazing, IMO. I haven't used Atom much, so I don't know if it's comparable, but I will usually set up several macros and compose them together to do mass edits of things.