vim Macros: Why and How-To!

  Рет қаралды 42,520

Luke Smith

Luke Smith

7 жыл бұрын

A quick vid on using vim macros. Put anything you want on simple recordable shortcuts real-time.

Пікірлер: 67
@aidhoss
@aidhoss 4 жыл бұрын
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-on5bt
@Chris-on5bt 4 жыл бұрын
The real gems of knowledge are in the comments. (Not to say Luke's video is bad by any stretch)
@yash1152
@yash1152 2 ай бұрын
> _"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)
@yash1152
@yash1152 2 ай бұрын
so, macro is just like an input buffer for sending to `:norm` command lol
@shigwig9751
@shigwig9751 7 жыл бұрын
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 :)
@ianpan0102
@ianpan0102 6 жыл бұрын
totally agree!
@MazDelaCerna
@MazDelaCerna 6 жыл бұрын
Great work! A lot of people don't know the hard work that goes behind creating on KZfaq so massive thumbs up!!
@artemcodes
@artemcodes Жыл бұрын
Thanks for simple and useful explanation 👍
@Karthik-yy6up
@Karthik-yy6up 3 жыл бұрын
Thanks a lot, very concise and to the point.
@maxuix2
@maxuix2 7 жыл бұрын
Before random string generators were invented, people asked a noob to open a file with vim and exit.
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
"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
@ReneHoffmann194
@ReneHoffmann194 6 жыл бұрын
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
@leandrocadete Жыл бұрын
Great!
@YannMetalhead
@YannMetalhead Жыл бұрын
Great tip!
@minsoehan7950
@minsoehan7950 2 жыл бұрын
Thanks for this video. Great.
@4932gb
@4932gb 3 жыл бұрын
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-hood5609
@zjardynliera-hood5609 2 жыл бұрын
this video saved my ass when I had to make an sh script over many files. Thanks man
@TomGrubbe
@TomGrubbe 2 жыл бұрын
Good stuff. Thank you!
@ewengoisot808
@ewengoisot808 6 жыл бұрын
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
@dinhof Ай бұрын
I always forget how to do it, and always get impressed I can do it :P
@Bahrta_sai
@Bahrta_sai 4 жыл бұрын
I can record & save something & you reinsert it using @[register] but how do I save it as a .vim macro?
@ChipAltmanxD
@ChipAltmanxD 6 жыл бұрын
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 (
@rakeshmanathana
@rakeshmanathana 3 жыл бұрын
That was great!
@fahadus
@fahadus 6 жыл бұрын
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.
@LukeSmithxyz
@LukeSmithxyz 6 жыл бұрын
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.
@greob
@greob 7 жыл бұрын
Nice. Have you thought about using an overlay showing key presses? That would be handy.
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
Yeah I usally do. Just forgot to here lol
@greob
@greob 7 жыл бұрын
Ah sorry, I forgot you used to do that before. :P
@migtrewornan8085
@migtrewornan8085 3 жыл бұрын
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).
@shifter65
@shifter65 2 ай бұрын
What would you use to repeat to the end of the file?
@thomasdehaeze3422
@thomasdehaeze3422 5 жыл бұрын
Thanks for this @@ tip :)
@breakername9995
@breakername9995 4 жыл бұрын
please continue to do videos :( i miss u
@alextrastero
@alextrastero 5 жыл бұрын
Perfect
@artaway6647
@artaway6647 6 жыл бұрын
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
@SHREEVATHSAVMUBEC
@SHREEVATHSAVMUBEC 5 жыл бұрын
Which terminal you are using?
@elliotalderson6609
@elliotalderson6609 2 жыл бұрын
what is the font do you have in your term?
@gjermundification
@gjermundification 3 жыл бұрын
@Luke Smith How do I say run this `@w` on all files in a folder?
@borsdev
@borsdev 6 жыл бұрын
Woooow man, how do you see image preview with vim?
@themindflayer5952
@themindflayer5952 6 жыл бұрын
Rodrigo It's not vim, it's another program called ranger. It's very useful.
@tahamagdy4932
@tahamagdy4932 5 жыл бұрын
I love you man
@brandonh7067
@brandonh7067 7 жыл бұрын
Are macros file-specific? Or will I be able to use the same macro in a different file (without re-recording)?
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
They're universal for all files until you overwrite them.
@psmit29
@psmit29 3 жыл бұрын
Which vim colorscheme is this?
@alkeryn1700
@alkeryn1700 7 жыл бұрын
Do you know how i can make an increment with it?
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
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.
@alkeryn1700
@alkeryn1700 7 жыл бұрын
Luke Smith exactly, i found it alone in the end but thanks :D I'm kinda new to vim but it is awesome xD
@feschber
@feschber 3 жыл бұрын
Why did i always fear macros lmao. It’s so simple
@CarlosAlbertoBrasil
@CarlosAlbertoBrasil 4 жыл бұрын
Anybody know How I record my crypt :X passoword? for encrypt my files faster
@bhaveshverma8629
@bhaveshverma8629 2 жыл бұрын
how to searching for string while recording a macro in VIM
@tianmax3407
@tianmax3407 5 жыл бұрын
Would you please introduce your Mac OS menu bar decoration?
@nberggie5784
@nberggie5784 3 жыл бұрын
this guy's on Linux
@kj-marslander
@kj-marslander 3 жыл бұрын
that's hilarious
@Lapester45
@Lapester45 3 жыл бұрын
this guy really said "Press @: capital 2"
@ejiek
@ejiek 7 жыл бұрын
Ranger preview is so broken in your term. urxvt handels it well ~.^
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
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?
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
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
@AnastasisGrammenos
@AnastasisGrammenos 7 жыл бұрын
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?
@LukeSmithxyz
@LukeSmithxyz 7 жыл бұрын
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.
@eduardoaranda4379
@eduardoaranda4379 4 жыл бұрын
Dude, it’s easier visual selecting and typing :norm @w
@421sap
@421sap 3 ай бұрын
God bless you in Jesus' Name Amen ✝️
@DrPastah
@DrPastah 5 жыл бұрын
I don't see why you need a macro. Just use regexp search and replace.
@LukeSmithxyz
@LukeSmithxyz 5 жыл бұрын
To illustrate how to do a vim macro for the purposes of a video tbh fam
@DrPastah
@DrPastah 5 жыл бұрын
​@@LukeSmithxyz lol
@migtrewornan8085
@migtrewornan8085 3 жыл бұрын
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.
@eset3649
@eset3649 7 жыл бұрын
Woa share that background please :D
@caremyok
@caremyok 5 жыл бұрын
naaası yabün laaaaaaaa
@TehKorwinMikke
@TehKorwinMikke 5 жыл бұрын
windows_bliss.jpg REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Start Turning vim into a /comfy/ IDE!
9:43
Luke Smith
Рет қаралды 206 М.
A Vid in which Vim Saves Me Hours & Hundreds of Clicks
10:23
Luke Smith
Рет қаралды 273 М.
1🥺🎉 #thankyou
00:29
はじめしゃちょー(hajime)
Рет қаралды 80 МЛН
Watermelon Cat?! 🙀 #cat #cute #kitten
00:56
Stocat
Рет қаралды 12 МЛН
1 класс vs 11 класс (неаккуратность)
01:00
TFW You Learn There's a Vim Mode in Bash...
6:55
Luke Smith
Рет қаралды 54 М.
Managing Your Splits In Vim
12:18
DistroTube
Рет қаралды 56 М.
Vim Navigation Commands
21:42
thoughtbot
Рет қаралды 112 М.
My Favorite Vim Tricks
14:39
MAKC
Рет қаралды 178 М.
Vim Can Save You Hours Of Work
20:52
DistroTube
Рет қаралды 169 М.
Why I Use Void GNU/Linux (And Why You Should, Too!)
8:20
waffles
Рет қаралды 7 М.
That One Micro Talk on Macros (NeovimConf 2023)
9:57
Jesse Leite
Рет қаралды 7 М.
10 Advanced Vim Features (You Probably Didn't Know)
21:47
Sebastian Daschner
Рет қаралды 65 М.
keren sih #iphone #apple
0:16
Muhammad Arsyad
Рет қаралды 558 М.
Очень странные дела PS 4 Pro
1:00
ТЕХНОБЛОГ ГУБАРЕВ СЕРГЕЙ
Рет қаралды 438 М.
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 19 МЛН
СТОИТ ЛИ БРАТЬ IPHONE 13 В 2024?
13:53
DimaViper Live
Рет қаралды 32 М.