A quick vid on using vim macros. Put anything you want on simple recordable shortcuts real-time.
Пікірлер: 67
@aidhoss4 жыл бұрын
Bonus: include `@w` at the end of the macro to make it recursively go to the end of the buffer. You can also dump the contents of a macro to a new file and edit it manually using `"wp`, then when you're finished with your edits load it back to the macro (which are just registers) with `"wy`. This is very handy if you've made an error in recording a macro and don't want to have to start again. Last tip: capital Q will append commands to the macro rather than re-record it from scratch.
@Chris-on5bt4 жыл бұрын
The real gems of knowledge are in the comments. (Not to say Luke's video is bad by any stretch)
@yash11522 ай бұрын
> _"to make it recursively go to the end of the buffer"_ ahww, the recursive here means calling itself. and better is "recursively do till end of buffer"... ohkay. niice :) (other meaning of recursive: recursive traversal of directories, or elements in json/dom etc)
@yash11522 ай бұрын
so, macro is just like an input buffer for sending to `:norm` command lol
@shigwig97517 жыл бұрын
this is my favorite channel because Luke seems like a super chill guy and has a ton of relevant information to share keep up the good work :)
@ianpan01026 жыл бұрын
totally agree!
@MazDelaCerna6 жыл бұрын
Great work! A lot of people don't know the hard work that goes behind creating on KZfaq so massive thumbs up!!
@artemcodes Жыл бұрын
Thanks for simple and useful explanation 👍
@Karthik-yy6up3 жыл бұрын
Thanks a lot, very concise and to the point.
@maxuix27 жыл бұрын
Before random string generators were invented, people asked a noob to open a file with vim and exit.
@LukeSmithxyz7 жыл бұрын
"I've been using vim for 20 years-back then I opened a file and I still haven't figured out how to close it!" -Rodney Dangerfield
@ReneHoffmann1946 жыл бұрын
Nice video. Maybe you don't know but you can skip the first steps by opening vim and do ":r !ls" to get the file list in vim.
@leandrocadete Жыл бұрын
Great!
@YannMetalhead Жыл бұрын
Great tip!
@minsoehan79502 жыл бұрын
Thanks for this video. Great.
@4932gb3 жыл бұрын
This is great. Soooooo much better than a seminar with bad audio,video, and standard neckbeard with heavy Brittish accent droning about how smart he is.
@zjardynliera-hood56092 жыл бұрын
this video saved my ass when I had to make an sh script over many files. Thanks man
@TomGrubbe2 жыл бұрын
Good stuff. Thank you!
@ewengoisot8086 жыл бұрын
2:05 actually, in this example, I can do it with a notepad like Gedit with Ctrl-h (search (you can use and regexpr) and replace), (of course, I'm not saying that gedit is as good as vim ^^)
@dinhofАй бұрын
I always forget how to do it, and always get impressed I can do it :P
@Bahrta_sai4 жыл бұрын
I can record & save something & you reinsert it using @[register] but how do I save it as a .vim macro?
@ChipAltmanxD6 жыл бұрын
Thanks Luke! I needed this to (easily) effectively change my mod key to spacebar in Sway, right there in the config file! And I'm jolly typing all these spaces without any extra effort! And did I mention my mod key is now SPACE!?!? jjkjjjjjjj (
@rakeshmanathana3 жыл бұрын
That was great!
@fahadus6 жыл бұрын
Just a fun fact. You can do something very similar and arguably faster in Notepad++ (bear with me.) After writing your first instance, like so: file 'filename.jpg' duration 5 copy from ' to 5 (Notepad++ copies line breaks as well without needing Regex, which was very handy when I used it) Now select a line break, by going to the end of the line and pressing shit + right arrow. Do a replace all with what we copied earlier. Voila! You can also do a search and replace on selection as well, but to keep things clean, I just copied whatever needed to be structured in a different file so I can just Ctrl+A+X it out. I know this is an eyeroll situation for many viewers of this video, but before I had discovered VIM, this little trick saved me hours of work on JSONs and CSVs.
@LukeSmithxyz6 жыл бұрын
I just wanted to show off macros. You can do the same in vim with these two regex commands: s/^/file '/g s/$/' duration 5/g which is pretty analogous to your solution.
@greob7 жыл бұрын
Nice. Have you thought about using an overlay showing key presses? That would be handy.
@LukeSmithxyz7 жыл бұрын
Yeah I usally do. Just forgot to here lol
@greob7 жыл бұрын
Ah sorry, I forgot you used to do that before. :P
@migtrewornan80853 жыл бұрын
I don't know why but although I'd very likely press 'j' '0' normally, if I was recording a macro I'd use '+' instead. It's only one less key press but for some reason I feel macros need to be as precise as possible (not sure what I mean by precise here).
@shifter652 ай бұрын
What would you use to repeat to the end of the file?
@thomasdehaeze34225 жыл бұрын
Thanks for this @@ tip :)
@breakername99954 жыл бұрын
please continue to do videos :( i miss u
@alextrastero5 жыл бұрын
Perfect
@artaway66476 жыл бұрын
Dang, I don't know vim is pretty smart to detect the last of the lines lol. Everytime I do macros I had to count the line length lol, even with relative number it is tedious
@SHREEVATHSAVMUBEC5 жыл бұрын
Which terminal you are using?
@elliotalderson66092 жыл бұрын
what is the font do you have in your term?
@gjermundification3 жыл бұрын
@Luke Smith How do I say run this `@w` on all files in a folder?
@borsdev6 жыл бұрын
Woooow man, how do you see image preview with vim?
@themindflayer59526 жыл бұрын
Rodrigo It's not vim, it's another program called ranger. It's very useful.
@tahamagdy49325 жыл бұрын
I love you man
@brandonh70677 жыл бұрын
Are macros file-specific? Or will I be able to use the same macro in a different file (without re-recording)?
@LukeSmithxyz7 жыл бұрын
They're universal for all files until you overwrite them.
@psmit293 жыл бұрын
Which vim colorscheme is this?
@alkeryn17007 жыл бұрын
Do you know how i can make an increment with it?
@LukeSmithxyz7 жыл бұрын
Yeah. Ctrl+a is vim's native shortcut for incrementing a number (ctrl+x is decrement). You can carefully work these into a macro that copies the last line and increments it, etc. which will give you increasing numbers, if that's what you're looking for.
@alkeryn17007 жыл бұрын
Luke Smith exactly, i found it alone in the end but thanks :D I'm kinda new to vim but it is awesome xD
@feschber3 жыл бұрын
Why did i always fear macros lmao. It’s so simple
@CarlosAlbertoBrasil4 жыл бұрын
Anybody know How I record my crypt :X passoword? for encrypt my files faster
@bhaveshverma86292 жыл бұрын
how to searching for string while recording a macro in VIM
@tianmax34075 жыл бұрын
Would you please introduce your Mac OS menu bar decoration?
@nberggie57843 жыл бұрын
this guy's on Linux
@kj-marslander3 жыл бұрын
that's hilarious
@Lapester453 жыл бұрын
this guy really said "Press @: capital 2"
@ejiek7 жыл бұрын
Ranger preview is so broken in your term. urxvt handels it well ~.^
@LukeSmithxyz7 жыл бұрын
Yeah it is; I've just gotten used to it tbh. I used to use urxvt but switched to termite for several reasons that I've now forgotten lol. Maybe I'll give it another chance?
@LukeSmithxyz7 жыл бұрын
Actually now I remember why I didn't use urxvt term: it had terrible compatibility with transparency on i3. But luckily, I jiggered around some settings and switched composite managers and finally got it working, so now I got transparency and not screwed up previews. Thanks for reminding me to finally do this lol
@AnastasisGrammenos7 жыл бұрын
Dude, you don't have to use composite manager if you are on i3. I just use: URxvt.transparent: true URxvt.tintColor: green ! or whateva URxvt.shading: 50 ! amount of transparency in my ~/.Xresourses This imitates transparency by taking a picture of what is behind the terminal and fading it with the tint you specified. Since in i3 you don't drag windows around this works wonders, and no need for memory hungry shitty composite managers! btw, politically, are you on the far right side of things, like the rest of 4chan?
@LukeSmithxyz7 жыл бұрын
urxvt's native transparency has never worked on i3 for me. Apparently it's a common problem. Again, that's the main reason I left urxvt in the first place. I use a composite manager for some other little things anyway and I've never felt like it bogged down my system.
@eduardoaranda43794 жыл бұрын
Dude, it’s easier visual selecting and typing :norm @w
@421sap3 ай бұрын
God bless you in Jesus' Name Amen ✝️
@DrPastah5 жыл бұрын
I don't see why you need a macro. Just use regexp search and replace.
@LukeSmithxyz5 жыл бұрын
To illustrate how to do a vim macro for the purposes of a video tbh fam
@DrPastah5 жыл бұрын
@@LukeSmithxyz lol
@migtrewornan80853 жыл бұрын
You can pretty much do anything a macro can using 'global' and/or 'normal'. Not that there's anything wrong with macros but I practically never use them myself - guess I just find other ways easier.