Skip to content

Instantly share code, notes, and snippets.

@hernamesbarbara
Last active June 5, 2017 22:34
Show Gist options
  • Save hernamesbarbara/5da8b5462f44c03bf33dbbf14ab514c6 to your computer and use it in GitHub Desktop.
Save hernamesbarbara/5da8b5462f44c03bf33dbbf14ab514c6 to your computer and use it in GitHub Desktop.
Macro to convert selected lines of text into a comma separated list

A macro to quickly convert lines of text into single line of comma separated values.

Usage - select/highlight some text in sublime. Type this command

super+, super+,

e.g. on a Mac command+, (command + comma) two times in a row.

INPUT

[email protected]
[email protected]
[email protected]
[email protected]

INPUT

[email protected], [email protected], [email protected], [email protected]

INSTALL

  1. Download the macro below and move it into your settings folder
mv add-commas.sublime-macro ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/
  1. Copy the keybinding to clipboard. Then in Sublime go to Preferences >> Key Bindings - User and paste it in there. Might need to reboot Sublime, but you should be good to go.
[
{
"args": null,
"command": "select_all"
},
{
"args": null,
"command": "split_selection_into_lines"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
},
{
"args":
{
"characters": ", "
},
"command": "insert"
},
{
"args":
{
"by": "characters",
"forward": false
},
"command": "move"
},
{
"args":
{
"to": "line"
},
"command": "expand_selection"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
},
{
"args": null,
"command": "left_delete"
},
{
"args": null,
"command": "select_all"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
},
{
"args": null,
"command": "left_delete"
},
{
"args": null,
"command": "select_all"
}
]
[{
{
"keys": ["super+,", "super+,"],
"command": "run_macro_file",
"args": {
"file": "Packages/User/add-commas.sublime-macro"
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment