Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using sublime 3 in Mac OS.

I want to convert

1
2
3

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
1  
tr '\n' ',' from the command line would be faster if you have many. –  slhck Jun 18 at 13:03

2 Answers 2

up vote 1 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
1  
Awesome, simply awesome!! –  Nitin Gurram Jun 19 at 10:10
1  
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 –  Nitin Gurram Jun 19 at 10:12

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

|1|
|2|
|3|

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])

|1| 
|2| 
|3| 

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.