IntroductionI use TextPad for text editing and one of the things I like a lot about TextPad is the Ctrl+J shortcut that allows you to join selected lines to each other. Visual Studio doesn't offer that line joining capability, so I decided to write it. CR_JoinLines adds a command ("Join Lines") that you can bind to a keyboard shortcut (Ctrl+J, Enter is what I use) and will join lines in the code editor. It also allows for an optional delimiter, so if you want a pipe or comma or some other string (yes, string - you're not limited to a single character) inserted between the joined lines, you can do that.
Installation- Make sure all instances of Visual Studio are closed.
- Copy the CR_JoinLines.dll assembly into your DXCore plug-ins folder. This is typically something like: C:\Program Files\Developer Express Inc\DXCore for Visual Studio NET\2.0\Bin\Plugins
- Open Visual Studio.
- From the DevExpress menu, select "Options," then "IDE/Shortcuts" from the treeview on the side.
- Add a new shortcut.
- Bind a key to the shortcut in the "Key 1" field ("Ctrl + Shift + J" is recommended).
- Bind a key to the shortcut in the "Key 2" field ("Enter" is recommended). This makes it so you have a two-key combination in order to execute the join. In this case, you'll type "Ctrl + J" then press "Enter" to execute the join. The second key is recommended in case you decide to allow for different types of line joins based on delimiter (more on this below).
- Set the shortcut's command to "Join Lines".
- Set the shortcut's context to "Focus/Documents/Source/Code Editor". (Hint: You can copy the "Code Editor" context from any existing command shortcut and paste it into your new shortcut by right-clicking.)
- CR_JoinLines allows you to optionally pass a string parameter to it as a delimiter to be used between joined lines. For example, if you want to join several lines into a pipe-delimited list, you could provide the pipe character as the delimiter. If you don't provide a delimiter, lines will just be joined directly together with no characters or space between them. To provide a delimiter, type the delimiter (inside quotes) into the "Parameters" box for the shortcut. For example, to have a pipe delimited join, type: "|"
- It is recommended that the default binding of "Ctrl + Shift + J", "Enter" provides a join with no delimiter parameter. To add additional types of joins - space delimited, comma-delimited, etc. - repeat steps 5 through 10, changing the second key binding (in step 7) to something intuitive and setting the appropriate delimiter parameter in step 10. It's easy to remember the delimiter if you set the delimiter and the second key to the same character. For example, a pipe-delimited join might have a key binding of "Ctrl + Shift + J", "|".
- Click "OK" to close the options window when you are done adding shortcuts.
Options
The following describes the recommended key bindings to set up during installation: | Binding | Command | Parameters | Context | Enabled | Send Key to IDE | | Ctrl+Shift+J, Enter | Join Lines | | Code Editor | True | False | | Ctrl+Shift+J, Space | Join Lines | " " | Code Editor | True | False | | Ctrl+Shift+J, , | Join Lines | ", " | Code Editor | True | False |
UsageOnce installed and bound to a keyboard shortcut (as noted above): - Open a text document in the code editor in Visual Studio.
- Without selecting anything, enter the keyboard shortcut to activate the command. The current line the caret is on will be joined with the subsequent line.
- Select multiple lines then enter the keyboard shortcut to activate the command. All selected lines will be joined.
CreditsAuthor: Travis Illig
|