Share via


SSMS tips - word wrap

Description

Line breaking, also known as word wrapping, is breaking the displayed of a section of text into lines so that the text will fit into the available width of the editor. When writing queries this feature is not so useful as breaking the script line may make the query less readable, but when writing long comments this feature become one of the most useful feature. This post simply shows you how to use word-wrap by default or add a command button to Toggle Word Wrap - it's a built-in feature which is less known and if you did not used it yet, then it is time to use the power of word wrap

Configure SQL Server Management Studio to use Word-Wrap by default

Click on "Tools" and open "Options"

Move to the: "Text Editor" -> "All Languages" -> "General"

Mark the option "Word wrap"

Click "OK" and you are ready

The problem with this approach is that this will wrap anything in the editor windows including the scripts -> this might be something that we will not want. We do not want to configure the SSMS each time that we want to read a long comment and configure it back not to use word-wrap when we want to read/write script.

The solution is to add a toggle button for the task...

   

Add Toggle Word Wrap button

Right click on the buttons tab and click on "Customize..."

Move to the "Commands" tab

Select the location of the new button: In bellow sample we add the button to the "Menu bar"

select "Menu bar" -> select "Edit"

Note! You can add the button to any existing menu or as new menu as well. The next image for example shows how we add the button to existing menu named "ariely.info", which is SSMS extension developed by the user. You can notice that we added it as a new group (you can see the line between the groups of buttons). Inmost cases, You will probably want to add it to the menu bar as shown in the above image.

Once you select the location for the button, Click on the "Add Command"

Find the command "Toggle Word Wrap"

and click "OK"

If you want to move the button to the end of the tools bar or any other location, then you can right click on the menu bar -> find the button where you added it -> use the buttons "Move Up" and "Move down" to put it in the right location

Credit

This article based on Ronen Ariely post, originally published here: https://ariely.info/Blog/tabid/83/EntryId/299/SSMS-tips-word-wrap.aspx 

See also