How do you use a macro to convert single quotes to double quotes?
qaf'r"q
Record a macro that finds the next single quote with f' and replaces it with a double quote using r".
qaf'r"q
Record a macro that finds the next single quote with f' and replaces it with a double quote using r".
qaf r_q
Record a macro that finds the next space with f and replaces it with an underscore using r_.
qa:s/^ / /\njq
Record a macro that substitutes leading 4-space indentation with 2 spaces on each line.
qa0d2Wjq
Record a macro that goes to the start of the line, deletes the first two words (timestamp fields), then moves down.
qaI"<Esc>A",<Esc>jq
Record a macro that wraps each line in quotes and adds a trailing comma.
qa*Ncgn<C-r>=newName\n<Esc>q
Record a macro using * to search for the word under cursor, cgn to change the next match, type the new name.
qa/[A-Z]\ni_<Esc>l~q
Record a macro that finds the next uppercase letter, inserts an underscore before it, and lowercases it.
qa0f=40i <Esc>040lDjq
Record a macro that inserts spaces before = to pad to column 40, then trims excess.
qaA,<Esc>jq
Record a macro that moves to end of line with A, types a comma, escapes to normal mode, and moves down.
qA...q
Use uppercase register letter qA to append to macro a instead of overwriting.
qaI1. <Esc>jq
Start at line 1, record a macro that inserts 1.
qa f,ldt,F(p q
This macro swaps two comma-separated arguments inside parentheses by cutting the second argument and placing it before the first.
u after macro (single undo)
When a macro makes multiple changes, a single u undoes the entire macro as one unit.
qaI<li><Esc>A</li><Esc>jq
This macro wraps each line in tags by inserting the opening tag at the start and appending the closing tag at the end.
Paste with "ap and execute keys manually
To debug a macro, paste its contents into the buffer, read each keystroke, and execute them one at a time to find where the macro goes wrong.
qaI"<Esc>A": "",<Esc>jq
This macro transforms a plain word into a JSON key-value pair format, useful for converting lists of field names into JSON structure.
qaciw"<C-r>""<Esc>wq
This macro wraps the current word in double quotes by changing the word, inserting quotes around the original content, and moving to the next word.
qaA;<Esc>jq
This macro appends a semicolon to the current line and moves down, ready to repeat.
qaI// <Esc>jq
This macro adds a // comment prefix to the beginning of the current line and moves down.
qa I1. <Esc>j q
This simple macro inserts a list number prefix at the beginning of each line.