How do I record a macro to add semicolons at the end of every line?
Answer
qaA;<Esc>jq
Explanation
This macro appends a semicolon to the current line and moves down, ready to repeat.
How it works
qa— start recording to registeraA;— append semicolon at end of line<Esc>— return to normal modej— move to the next lineq— stop recording
Example
let x = 1
let y = 2
let z = 3
After qa A;<Esc>jq then 2@a:
let x = 1;
let y = 2;
let z = 3;
Tips
100@aadds semicolons until end of file (stops at last line)- Check first that lines do not already have semicolons
Ais better than$abecause it works on empty lines too- Modify the macro for different suffixes (commas, colons, etc.)