free web page hit counter
🛡️
Copyright Notice: This video is officially sourced and embedded from YouTube. For all copyright inquiries, reports, or removals, please contact YouTube's legal team here.
typecraft

typecraft

229,000 subscribers

👁 115,300 views

This VIM trick BLEW MY MIND

Video Overview & Insights

LEARN: https://learn.typecraft.dev/tutorial/editing-a-vim-macro/

thanks nerd

— @frknue

Join the stream! https://twitch.tv/typecraft

Join the community: https://discord.gg/TfPqD3MWVq

ggVG (select whole file)
:norm A, (append , every line)
gv (reselect last selection)
gJ (join lines without separator)

— @Badosureinhardt

X: https://twitter.com/typecraft_dev

I've been using vim for 10+ years now, and I gotta say, I still learn something new every once in a while. And recently, I realized something about macros, and registers, that BLEW MY MIND. Check out this video on why vim macros and registers are probably a LOT simpler than they seem.

Of course, sometimes macros are overkill, for example if you just wanted to do the same for every line in the file you could just do: ":%s/$/,/|%j"
That is for every line use regex to substitute the end of line ($) with a comma, then (pipe) for every line (j)oin. If you don't want a space added you can just do "%j!"

— @Mu77ley

More User Perspectives

@

20J is enough vro 🥀

@RenderingUser
@

Come on dude, you click bait "This VIM trick BLEW MY MIND" and it's just a hidden advertisement for your learning platform. There's nothing mind blowing about making a basic macro... At least some comments here were actually useful/new information.

@thenewpotato61
@

i don't use the :put a, i just paste my register anywhere, with "ap then edit it, and yank it again

@malmiteria
@

I think with most of this stuff, you have to think "how would they have written this in the 70s?" and then you'll realize, yea it was all just ASCII text everywhere..

@1980Hiawatha
@

why all developers who wear mustage are telling me why vim is so peak?

@qdrion3293
@

Thank you for this tip. So basically everything is just text stored in a register, even macros.

You can write out the exact sequence of characters you want for the macro, then yank it into a register using "ayy, which yanks the whole line into register a.

After that, you can run the macro with @a.

Pretty cool stuff. I’m wondering how I can visualize it faster and learn more about special keys, like how Escape takes you from insert mode back to normal mode.

@nguyenhoangminhtrung
@

^v6j$A,^[VGJ

@SeafoodFriedRice
@

Someone already mentioned it, but for posterity: you know how you can put a number in front of any command key in vim? Like 5j will move down 5 lines? Or 7dd will delete 7 lines? Well even with registers, you can type 7@a and it will do that macro 7 times. Not only that, but I believe macros can call other macros too

@whatsnextforkev
@

You don't even need to do use :put a, you can just do "ap.

@dj_chateau
@

@@ replays the last macro. So @a then @@ after that.

@jasonfreeman8022
@

Holy shit I did not know that. This makes so much sense. Thanks.

@uoweme5grand
@

Pro tip:
If you noticed, Escape is shown as
^[

which is the same representation as key combo Ctrl+[
And guess what, instead of escape, in Vim you can always use Ctrl+[ and it'd behave the same :)

This is especially useful because pressing the escape key to exit modes is often annoying as the escape key is very far from the rest of the keys.

@Ben-rc9br
@

I know this is just an example / demonstration, but for any newbs watching...
8J would have done this in a second or two without registers. As in, number 8 (-ish), capital J, in Normal Mode. Two keystrokes.

Thanks, Nerds. 👋

@artvandelay5028
@

imagine someone making this tutorial, and when showing the registers, something crazy shows up

@satoijidesu
@

q for qreate maqro

@satoijidesu
@

One year later and not a single comment about going to the grocery store to buy meth.

@fraternitas5117
@

Great video ! Thanks!

@smidamarwen8033
@

the 'q' register is classic tho

@devmindscapetutorials
@

for that use case i'm using vap then :norm A, <ESc>J

@dagoberttrump9290
@

I'm sorry WHATS THAT on your SHOPPING LIST?!

@Fazal828
@

What does this " yanked " thing mean?

@xiic_17_chiragagarwal30
@

"So if I just take @a @a @a"

You can replay the last run macro with @@

@crow-dont-know
@

Typecraft: What's the easiest way to do this?
Me: %s/\n/, /g
Typecraft: The easiest way is to create a macro
Me: Oh

@crow-dont-know
@

Two quickie suggestions to make applying your macro even more efficient: (1) execute the macro once and then repeat with @@ rather than moving your fingers over the keys to hit @a over and over, or (2) better yet, execute the macro a number of times by using a count, such as 6@a instead. Cheers!

@Phileosophos
@

brodie what's up with the wifi name

@lung-notification
@

Vim is hard to learn and hard to master lol. And absolutely worth it for some people 🫶

@anoni-mouse-on-nix
@

I've been coding in Vim for years and only this week did I learn about this and the amazing norm command.

@BluesManPeich
@

kiwis and meth. My favourite breakfast

@pedroquerido2268
@

Nice video - didn't know about editing macros/registers before. I do have one small tip that you might find that improves on using macros and that's the :map command. Essentially, what I like to do is to do something like ':map = <macro>'. In the example given here, that would become ':map = A,^[J' (without the quotes, of course) to store the macro under the unused equals key. Now you only need to hit ONE key to perform the macro however many times you need to. I'm a touch typist and this is quite a bit faster because I'm not having to awkwardly reach for the shift key all the time.

@nosuchuserid
@

You can also provide a number to replay the macro # times. rather than press "@a" six times you could press "6@a".

@dangeroushobo
@

Going @a@a@a@a... Is a lot of wasted key presses. Just do <x>@a where <x> is the number of times you want to run your macro. 😌

@SirWrexes
@

Just reflow paragraph to bring everything in one line then just prepend words with , - done

@mateuszabramek7015
@

there is an awesome FREE book online “lazyvim for ambitious developers” just saying…. the best place to start

@spamcolector
@

just use vscode

@girinchutia1382
@

Very nice !

@sep69
@

Tip: If you're on a regular keyboard, @<register> is a bit clunky to type when you want to execute your macro quickly.
To replay the last recorded macro, just go @@
If you know how many times you need to execute it (say 5), do 5@@

@chmikr
@

Holy shit, this is really cool to know. I can plan my macro while seeing it, then dd@0 (or even have a binding that deletes the row and executes it as a macro immediately.

@Tekay37
@

Yup, as someone actively learning this is a great insight

@SoreBrain
@

Two years later, after watching and applying your tutorials , YOU ❤ changed many concepts for me to the better even in my life , which reflected my speed and thinking .. writing the code, of course, and focusing on solving the problem instead of focusing on the place of the cursor, as an example, actually I don't need to use the mouse anymore 😎🤘.. Previously, I was a normal programmer, and now I am like Neo in the matrix film 🎉 . I wish you all the best from my heart❤🥹🤜🤛

@MegaOsama99
@

Pubert 😂

@debrucey
@

Didn't know Ted Lasso was a vim expert :D

@JuliusUnscripted
@

main takeaway: "i'm yanking all over the place"

@muskyoxes
@

You can also just register another macro that calls the A macro with J, and record that. But honestly, this whole complicated thing for « just » doing something so trivial is what makes me realize today that Vim is outdated. I use Kakoune and what you described here that you wanted to do is just a couple keypress in Kakoune without needing to think about registering commands or editing registers:

%<a-s>;c,

(those are actual keys I press, and all of that is visually activated, for a nicer feedback). So yeah, I started coding 22 years ago, quickly picked up on Vim, but today, when you look at what other editors / philosophy provide… Vim is seriously outdated.

@DimitriSabadie
@

You seriously need to be a nerd if you are getting impressed by vim keybinds

@greNxNja13
@

"easy to learn, hard to master"
No. Its definitely "hard to learn, harder to master" for vim...

@kunai9809
@

I’ve would have done your first example with a search and replace regex. One line and done.

@marsrocket
@

0:20 famous last words vim is easy to learn

@jemolife15