Incrementing Numbers in Vim1:17
So let's visually select these again, and this time I'm going to type G Ctrl A, and now you'll see it's incremented each line one more than the next. If we undo that, let's go to another visual selection and come down to the bottom. I'm going to use Shift I to insert another zero in the front here, and let's now select all of those again, and let's try our G Ctrl A again, and you'll see that it preserves our leading zero. So that's pretty handy if you need to fill out a bunch of lines with some incrementing numbers. Next up, I want to give you a taste of macros. So let's go into this movies.json file that I've created, and let's say we want to turn
Recording a Macro for HTML1:49
Next up, I want to give you a taste of macros. So let's go into this movies.json file that I've created, and let's say we want to turn this JSON file into HTML, where the title of each movie is inside a h2, and the release year is in brackets afterwards. So let's go ahead and remove the top two lines, and we'll come down to the bottom and remove those bottom two lines as well. So now we have three pairs of movies that all follow the same structure. With my cursor on the first line of the first movie in the zeroth column, I'm going to press Q followed by Q. Now the Q key tells Vim to record a macro, and the second Q we pressed tells it what
Inspecting and Pasting Macros4:46
let's just firstly type in register Q, and this will show us the contents of our Q register. So this is all of the text involved in that macro. If I want to paste from the register, I can use ", and then the name of the register, so in this case Q, and then I'll type P, and that will paste that register into my buffer here. I could then come over to these H2 tags, and maybe I actually want to use Ctrl A to increment that one. And let's come back here, and we'll increment this one as well. We don't have to have our cursor exactly on the number.
Editing and Saving Registers5:14
And let's come back here, and we'll increment this one as well. We don't have to have our cursor exactly on the number. It'll do the next one on the line, so I'll do another Ctrl A there. So both of our tags are incremented. And I'm not sure why I wrote the closing tag before the opening tag, but there you go. I can now put this back into a register. So if I come over to the start of the line here, and I select the register I want to place this in. So I could type ", and let's say w, and then YY to yank that line.
