Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using sublime 3 in Mac OS.

I want to convert


to 1,2,3 using keyboard shortcuts. or any plugin which can convert vice versa with keyboard shortcut. I don't want to press 10 keys to make this happen and that too much confused keyboad of MacBook.

Please let me know, how can I configure Sublime/plugin which can do?

share|improve this question
tr '\n' ',' from the command line would be faster if you have many. – slhck Jun 18 '14 at 13:03
up vote 2 down vote accepted

In sublime text three, you can do this by selecting all (command+A), Split into lines (command+shift+L), click the right arrow, type a comma, click left arrow twice, click delete, Expand Selection to Line (command+L), click the right arrow, and hit delete. However, you stated that you wanted a keyboard shortcut for this. You can find a copy of a macro I created here. You want to put this file in

~/Library/Application Support/Sublime Text 3/Packages/User/

Once that is there, go back to Sublime and click on the menu item Sublime Text, Preferences, and Key Bindings - User. Paste this into the document that opened and save it.

[ { "keys": ["command+option+,"], "command": "run_macro_file", "args": {"file": "Packages/User/add commas.sublime-macro"} } ]

The default key combination I put is command, option, comma. To change the keyboard shortcut, change the text inside the square brackets [ ] keeping the spaces after each combination. Save the file, and go back to the document you wanted converted to CSV. Press your keyboard combination, and you're good to go.
Hopefully this works, if not, or you have other questions, share them and I will try to answer them.

share|improve this answer
Awesome, simply awesome!! – Reddy Jun 19 '14 at 10:10
Can you make one more macro for this type of data | 1 | <new line> | 2 | <new line> | 3 | to 1,2,3. Replace all |<space> and comma seperate the rest – Reddy Jun 19 '14 at 10:12

For the number inside the vertical bar, and no space before each new line (e.g)


you can find a macro for that here.

For the number inside the vertical bar and a space before the new line (e.g [note the spaces])


you can find a new macro here. You need to add these to the same place...

~/Library/Application Support/Sublime Text 3/Packages/User/

and once again modify the User's key bindings. This time, the Key Bindings file should look something like this...

[ { "keys": ["command+option+,"], "command": "run_macro_file", "args": {"file": "Packages/User/add commas.sublime-macro"} }, { "keys": ["command+option+shift+,"], "command": "run_macro_file", "args": {"file": "Packages/User/with spaces.sublime-macro"} }, { "keys": ["command+option+function+shift+,"], "command": "run_macro_file", "args": {"file": "Packages/User/no spaces.sublime-macro"} } ]

You can find a copy of the file here. This file, as you may have noticed, goes in the same location as the macro files (~/Library/Application Support/Sublime Text 3/Packages/User/). Once you have that there, you can take out some of the macro shortcuts by deleting from "keys" to the }}, part, or you can add or edit the keyboard shortcuts. If you need any other macro, you can create a macro by clicking tools and record macro (control+q), and then stop recording macro (control+q again). Then you can hit save macro and save it in the default location (~/Library/Application Support/Sublime Text 3/Packages/User/). A macro is a single instruction that expands automatically into a set of instructions to perform a particular task. Hopefully this works, and if you have any other questions I'm glad to help.

share|improve this answer

You can do it with a regex using Replace All.

Find What: \n 
Replace With:,

Note: you must have regex mode enabled.

share|improve this answer
Shortcut means usually combination of keys to achieve something. :P I don't have to take the longest path something like this – Reddy Sep 3 '15 at 15:10
If you're doing it in succession and you already have the correct values populated in Replace All, then you can use CTRL+H, CTRL+ALT+ENTER. – Alex Sep 3 '15 at 15:34
Or create a macro based on it. – Alex Sep 3 '15 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .