viernes, 26 de agosto de 2022

Vim and Vscode to camelcase

Earlier today I saw a post on vscode subreddit where the author explores a plugin to transform parts of the code from/to camel/snake/kebab case.

Automatically I started thinking how I'd do it in emacs/vim. Given I'm lately not doing so much text munging as I used to, I feel a bit rusty wrt editing-fu. Let's see...

In the video, the guy uses something like multiple-cursors to select the area from the beginning of line till the colon. That was the most difficult thing to me, because neither vim nor emacs have multiple cursors without installing a plugin.

So, I though there had to be a "declarative" way (whatever it means) to do it, and thought of a regexp that would convert the _x to X , for all _ before a colon.

It turns out I could do it quite successfully with vim, just researching a bit how to do lookaheads.

I took 

foo_bar_f: foo_bar,
foo_bar: foo,
foo_bar_: foo  

as my test case, because it has underscores in both sides, it has missplaced underscores, and different lenghts (so we can't use visual block)

This is what I came up with. Visual select and

:s/_\(.\)\ze.*:/\U\1\L/g

I was a bit surprised that it took me a bit longer than expected, and that I had to use a few "advanced" regex features.  

I haven't tried to do it in emacs yet.  Any ideas? Any simplification to my solution?

viernes, 19 de agosto de 2022

java time

This is so helpful that I'm just putting it here for future reference.

https://stackoverflow.com/questions/32437550/whats-the-difference-between-instant-and-localdatetime