DEV Community

Discussion on: Vim: from foe to friend in 9 minutes

omerxx profile image
Omer Hamerman Author

Hey Vic,

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>@@)

Thread Thread
viccw profile image
Vic Seedoubleyew

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?

Thread Thread
omerxx profile image
Omer Hamerman Author • Edited

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.

Thread Thread
viccw profile image
Vic Seedoubleyew

Thanks for the swift reply!

After thinking about all of this, my conclusion is the following:

  • I don't see how macros can change much my productivity
  • not having to move my wrists to the arrows, and using mainly the home row instead, is conversely a killer feature, which I can see making me a lot faster
  • the problem I have with switching is the following. Muscles only have a single memory. If I switch my muscle memory to vim, it means I will be very slow outside of vim. Which means either I have to go to vim every time I want to type anything, such as replying to each email, or I have to suffer frustration each time I type something outside of vim. If there was a way to change system-wide input settings to use an "embedded vim", I would definitely make the switch

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.

Thread Thread
omerxx profile image
Omer Hamerman Author

Hey Vic,

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.

The same goes for IDEs obviously and many more...

Thread Thread
viccw profile image
Vic Seedoubleyew

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?

Thanks a lot again!