DEV Community

Cover image for March 19th, 2021: What did you learn this week?
Nick Taylor
Nick Taylor

Posted on

March 19th, 2021: What did you learn this week?

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

![Yoda wooping someone's butt](https://media.giphy.com/media/yDYAHbqe5DfyM/giphy.gif)

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

#todayilearned

Summarize a concept that is new to you.

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

![Little kid making a fist as if to say "Yes!"](https://media.giphy.com/media/6brH8dM3zeMyA/giphy.gif)

Top comments (17)

Collapse
 
vonheikemen profile image
Heiker • Edited

Ooh. This one was interesting. This is a two part story.

1) So, zsh has a "vi-mode" built-in, and it turn out is not as useful in practice.

2) The bindkey command has an option -s that lets you map two key sequence.

Say I want to have a keymap, ctrl+x + s, to make zsh type sudo for me. This is how it goes.

bindkey -s '^xs' 'sudo'
Enter fullscreen mode Exit fullscreen mode

The ^ thingy, means ctrl. That would work. But it can be better, because you can have the "special" sequence in the other side too. We can get fancy.

bindkey -s '^xs' '^asudo ^e'
Enter fullscreen mode Exit fullscreen mode

^a means ctrl+a, so that would get you to the beginning of the line and type sudo for you. Then, ^e will get your cursor to the end of the line. I would say that works fine 95% of the time. The other 5%, is when the original position of the cursor wasn't the end of the line. Can we do better? Yes, remember the "vi-mode"? That works too.

Behold.

bindkey -s '^xs' '#^asudo ^x^vf#xi'
Enter fullscreen mode Exit fullscreen mode
  • #: Its literally #, nothing special here.

  • ^a: Go to the beginning of the line

  • sudo: You know it already.

  • ^x^v: Enter vi-cmd mode. That is ctrl+x + ctrl+v. Not the most intuitive thing in the world.

  • f#: Remember, we are in "vi-mode." In here the character f is a command, a search command. What does it search? The next character we type. So, this will search for a # and get the cursor to that position.

  • x: Deletes the character under the cursor, which should be #.

  • i: Get us back to insert mode.

And there you have it. Now you can use ctrl+x + s to add sudo to a command you're currently writing, and it will take you back to the place you started (that is of course if you don't any extra # in your command already).

While on the subject of crazy keybindings I present these.

bindkey -s '^xf' '#^e | fzf^x^vF#xi'
bindkey -s '^xp' '#^e | less^x^vF#xi'
Enter fullscreen mode Exit fullscreen mode

You can guess what they do.

EDIT: By the way, fish users already have something like these. I believe Alt+p will add | less to your command. Don't remember what others they have.

Collapse
 
nickytonline profile image
Nick Taylor

Hot Rod saying Cool beans!

Collapse
 
atulcodex profile image
🚩 Atul Prajapati 🇮🇳
Collapse
 
nickytonline profile image
Nick Taylor

Nice!

Actor from Game of Thrones saying Nice!

Collapse
 
atulcodex profile image
🚩 Atul Prajapati 🇮🇳

Thank you nick ;)

Collapse
 
nald profile image
Nald • Edited

I learned that axios onuploadprogress and ondownloadprogress doesn't work when you are not in the browser, still finding the alternatives

Collapse
 
nickytonline profile image
Nick Taylor

The More You Know NBC TV campaign video capture

Collapse
 
peter279k profile image
peter279k

I learn how to use the Python requests, BeautifulSoup to complete a auto filled scheduler and help me to fill working schedule time automatically 😃.

Collapse
 
nickytonline profile image
Nick Taylor

A bowl of soup with the pun at the bottom of the image “Feeling Soup-er”

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

doppleganger node packages. I was creating a UI Kit and mithrilj s was getting loaded twice causing lots of things in my app to break.

Collapse
 
nickytonline profile image
Nick Taylor

Oof.

One of the Wiggles waving to themselves

Collapse
 
maureento8888 profile image
Maureen T'O

Honestly, getting events and props into my head after months of learning my favourite framework 😅🥳

Collapse
 
nickytonline profile image
Nick Taylor

That's awesome! 🔥

Yes, that's awesome!

Collapse
 
mathieuhuot profile image
Mathieu Huot

Aaah, beautiful Montreal! (off topic)

Collapse
 
nickytonline profile image
Nick Taylor

It's True - Dwight Shrute

Collapse
 
kirkcodes profile image
Kirk Shillingford

Solving coding challenges with parser combinators!

github.com/tkshill/protein-transla...

Collapse
 
nickytonline profile image
Nick Taylor

Awesome!

Hackerman from Kung Fury putting on a Nintendo Power glove