Here is the macro you are looking for,
[
{ "command": "select_all", },
{ "command": "split_selection_into_lines" },
{ "command": "insert_snippet", "args": { "contents": "\"${0:$SELECTION}\"" }, },
{ "command": "move_to", "args": { "to": "eol", "extend": false }, },
{ "command": "insert", "args": { "characters": ","}, }
]
This is what the macro does:
- It selects all the text.
- It creates a selection for each line, placing a cursor at the end of each line.
- It wraps the text of each line in double quotes.
- It moves the cursors to the end of each line.
- It inserts a comma (
,
) at the end of each line.
The macro file must be saved with a .sublime-macro
extension in your User
directory (if you're not sure where that is select Preferences --> Browse Packages...
from the menu). The file can be named anything you like but descriptive names are usually best since they prevent later confusion, e.g. QuoteAndComma.sublime-macro
.
You can run the macro from the Sublime Text menu Tools --> Macros --> User --> QuoteAndComma
, but here is a key binding to make it easier to use.
{
"keys": ["ctrl+shift+alt+5"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/QuoteAndComma.sublime-macro"},
},
Add this to your user key bindings file changing the keys to whatever you want. Note that the example key binding assumes that you saved the aforementioned macro file as QuoteAndComma.sublime-macro
in the User
directory.
When this has all been done, when you press the key binding, the text on each line is double quoted and a trailing comma is then added.
As an additional note, you can also use the following series of default key bindings to perform the same actions that are in the macro file.
- ctrl + a -> Selects all text.
- ctrl + shift + l -> Split selection to lines.
- shift + " -> To double quote.
- End -> To move each selection to eol.
- , -> The final trailing comma.
Finally, just in case you were replacing one by one before, in the find/replace panel you can select Replace All
to perform all the replacements in one go.