We're a place where coders share, stay up-to-date and grow their careers.
Thank you for this article, and congratulations on having had the courage to take several years to get a grasp of vim.
I am very sensitive to my productivity, so anything that can make me faster makes me very interested. To give you an example, I almost never use the mouse, I use keyboard shortcuts as much as possible.
Sadly, after reading this article I still don't get what Vim can bring me, that my IDE cannot. I still don't see how it can make me faster.
Could you please share some concrete examples of things that vim can do, that IDEs don't? Or things that vim can let you do faster?
To give you examples of why so far I don't have this answer:
text navigation: in any text editor on my Mac, I can use Option + Arrows to navigate word by word, Cmd + Arrows to go to beginning or end of line, or to beginning or end of file. I can use Shift + Option + Arrows to select text word by word and Shift + Cmd + Arrows to select the rest of the line, to beginning or to end. Additionally, using Cmd + F I can search for a word and navigate there directly.
repeated typing: in my IDE, I hit Cmd + Option + R on a class' field, and it refactors it everywhere, not only in that file, but everywhere it's used in my project. In most text editors, I can type Cmd + H or Cmd + F, and it replaces all occurrences of a word by what I want. In my IDE I can provide a regex for that.
I even find that these shortcuts are more handy than in vim, because I don't have to reach for the Escape key, my thumbs are already on the Cmd key, my hands don't need to move much.
To avoid any misunderstanding on my question:
Thanks a lot again for this article, and thanks in advance for your clarifications!
Hey! And thanks for raising the discussion because there are great questions.
I'll try to answer to the best of my understanding.
There is no claim that IDE's as a general concept are all inferior and cannot do what Vim does. Vim has a very profound concept of motion that is designed to make you faster.
For example, you mentioned the motions you use when moving in a line. In Vim, while it's obvious your mouse isn't playing a role at all, just reaching for your kb arrows is considered a big no-no. The motion is designed to keep your wrists in the exact same position, while only moving the tips of your fingers. Arrows are considered a complete finger context switch. And so motions are being used with hjkl (hard to get used to, but once you do you won't go back to taking your fingers away :) )
Another point in the motions you described in the first question is only involving a specific line. Try to consider moving in a large text file (or a code file for that matter) where you have to jump between definitions or methods. Vim always tried to involve the shortest way such as typing <number of lines>+<down motion (j) or the use of marks. The same goes for the Vim quick search and navigating between results with motions that won't draw your fingers away. You can even take it a step further and use the motion plugin.
<number of lines>+<down motion (j)
Another powerful motion is f (find) and F (find backward) which lets you find the next char in front or behind the cursor. And so moving to the next space (or next 3 spaces for that matter) are a chain of number and find motion. This goes for anything and is one of my most used motions in Vim, which when writing text in another editor (like at this moment for instance) I find it very hard to use without my superfast options..
If you're really into learning it you can try reading the docs or reading the matching section in Drew Niel's book (mentioned in the post).
When it comes to repeated typing, Vim is super useful, mastering macros allows a super-efficient way of refactoring code and custom changes where a simple multi-cursor concept won't do (which by the way Vim implements really nicely too).
To conclude I'd add that Vim's idea of doing stuff is a number of repetition followed by a motion followed by a target (char / word / line / code block / page etc...). If you know how to handle even a few it makes you a wizard of motion and efficiency.
To me, it was the difference of translating my thoughts into code (or text) in the same speed my mind works. Which also contributes to the flow of work and creation.
Hope this helps or answers your questions :)
Thanks a lot for taking the time to address my questions.
This reply helps a lot. I start to understand some of the benefits of using vim. Not having to move my wrists can definitely speed up things tremendously.
Could you please share an example of "mastering macros allows a super-efficient way of refactoring code and custom changes where a simple multi-cursor concept won't do". I still don't have a good picture of what that can be.
Thanks a lot again!
With any other tool you'd have to go one by one, maybe you'll be able to search for function and maybe be able to add the prefix of async but how about a last optional argument?
With Vim the logic for a macro would be this:
I async <space>
Now, if you @q Vim will perform all of the above on the second appearance of function and will end on the next one. if you @@ it will do once again the last used macro.
If you 50@q you'll run this 50 times more. Assuming you have less than 50 of them, and that function is generic enough in JS to indicate a function and will not appear anywhere else in the file (in other case you have to fix your initial search target), you've quickly editted a file regardless of the size with the exact change you wanted.
While this may seem very specific, I can't stress enough how useful this is. When you deal with huge json or yaml files this is like a magic wand.
You can also combine this with NERDTree to visually walk through any other file (maybe even with specific naming) to edit multiple ones.
You can even edit your macro by reading the register q and saving it again (will not explain here unless you really want to dive into it) and use it later, or just fix stuff.
Thanks a lot once again for taking the time to share insights with me. I really appreciate it.
About processing large json or xml files, this has never happened to me, and I guess this is pretty rare for standard software engineers.
Don't get me wrong, I am not trying to argue here, or prove that vim is not useful. I am really genuinely interested in understand specifically what benefits it can offer me, and other typical software engineers.
Thanks again very much for your help!
No worries at all! I totally get you.
I think what's important here is that you learn what you need. If you don't feel you have repetitive refactoring work then there's no need for you to dive into it.
Macros in Vim are a relatively very easy thing to learn so I think spending the hour and adding them to your arsenal of Vim magic is a good thing.
I think I find myself using a macro once a day. Sometimes it could probably done with a regex replacements statement (%s/<pattern-to-replace>/<replacement>/g) and sometimes with multiple cursors which I find to be more dangerous then helpful.
Thanks again for your reply.
About not feeling that I have a need, I think one does not need to feel the need. Very often, one doesn't image that one could go faster. This is why although I don't imagine how I could be faster, I would love to get examples that I don't picture yet.
About refactorings, I never use multiple cursors. However I very often use IDEs' rename variable, rename field, rename method, rename class, move class, etc, tools
One example I used today: I'm building our product's backend and am testing it both with unit tests and mocks of calls and both with sending real-life requests from postman.
The request is a 100 line JSON, and we agreed yesterday about removing a specific nested field from specific locations in the request. I've created a macro that searches for the constant field about each set of actual fields needed deletion (/<field>/) then, I created automation for deleting it (this was specifically "go 3 lines down, remove the trailing comma, then delete the line below" since this should be a valid JSON). So: 3jEx (3 lines down, End of line, delete char), and jdd (line down delete line). Now, all I had to do is find the next (n) appearance of my search index, and run the macro as the number of nested objects I have (<#_of_objects>@@)
Thanks a lot again for your reply! I really appreciate your taking the time to share your experience.
I am not exactly sure, but wouldn't see be doable with a simple search and replace with regular expressions in an IDE? Something that would take a variable number of white space before your field, and an optional comma if the next character is not a closing bracket?
Depends, sometimes it is sometimes it isn't, regex on its own when trying to achieve complex solutions is hard.
Many times a macro is just a faster simpler solution which allows you to think like a human being, and sometimes the only way is a macro. Search and replace is a single specific use-case, not a substitute to all macro powers.
Thanks for the swift reply!
After thinking about all of this, my conclusion is the following:
I guess the situation is a bit the same as with switching to a Dvorak keyboard layout. I tried it before, and then I realized that I couldn't set it up on my phone, so I was super slow and frustrated on my phone. I moved back to a standard keyboard layout just because of that.
Basically I agree with the last 2 statements. With the first one not fully but I can only send you to the docs where you may find something I didn't say :)
About the "problem" with moving out of Vim, I agree but you'd be surprised to know that since Vim is deeply integrated a long time into any *nix system it's convention keys can be found almost anywhere. Even modern mail clients like SuperHuman integrated Vim shortcuts by default...
Personally I use the same for everything, even my MacOS desktops are configured to switch with Vim hjkl.
Another example is the terminal which can be set with set -o vi to provide Vim motions within the lines.
set -o vi
The same goes for IDEs obviously and many more...
Thanks again very much for taking the time to clear things out for me. I really feel lucky to receive such guidance.
One crucial point for me is the ability to use Google Docs and Gmail. I tried looking online but so far haven't found any really good solution. VimAnywhere seems to be good for short non-formatted input fields, but not very convenient with Google Docs.
Would you by any chance have something to suggest?
We're a place where coders share, stay up-to-date and grow their careers.