Is there some magical way to have SublimeText handle a line like this automatically for me?
print('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dapibus mauris urna, in semper dolor semper eget. Proin condimentum est sed est elementum, eu pulvinar eros malesuada. Quisque malesuada sapien et quam convallis, et sodales risus blandit. Vestibulum auctor justo eu libero pellentesque tempor. Quisque faucibus augue eu fermentum auctor.')
I'm honestly indifferent of it coming out like this:
print('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dapibus'
'mauris urna, in semper dolor semper eget. Proin condimentum est sed est'
'elementum, eu pulvinar eros malesuada. Quisque malesuada sapien et quam'
'convallis, et sodales risus blandit. Vestibulum auctor justo eu libero'
'pellentesque tempor. Quisque faucibus augue eu fermentum auctor.')
or like this:
print(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dapibus'
'mauris urna, in semper dolor semper eget. Proin condimentum est sed est'
'elementum, eu pulvinar eros malesuada. Quisque malesuada sapien et quam'
'convallis, et sodales risus blandit. Vestibulum auctor justo eu libero'
'pellentesque tempor. Quisque faucibus augue eu fermentum auctor.'
)
or any other 'pythonic' way to handle a long string. Basically I want to write a long string, highlight it, and hit a button and find it is magically formatted some acceptable way. I would also really like to have some way to edit this string once it's already made without doing the work all over again.
Currently what I do is write this string, use Wrap->Wrap at X characters, then go through manually and add quotes to the start and end of each line and also adjust the indenting if necessary. If I want to edit, I have to then go and remove the starting and ending quotes in each line, concatenate it to one line, fix it, then do it all over again. It's awful.
To wrap your selected content with a html tag, just selected your text, then press Alt-Shift-W.
Select the paragraph and Ctrl+J.
It is possible to make multiple single-quoted lines like in your question, but you need to join them in the print statement:
print('long line 1' + \
'long line 2' + \
...
)
and it'd be a huge amount of work to undo that every time you wanted to edit the strings. So, why not just use a triple-quoted string?
print("""Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent
dapibus mauris urna, in semper dolor semper eget. Proin condimentum est sed
est elementum, eu pulvinar eros malesuada. Quisque malesuada sapien et quam
convallis, et sodales risus blandit. Vestibulum auctor justo eu libero
pellentesque tempor. Quisque faucibus augue eu fermentum auctor.""")
First, enter your mega-text on one line. Then, select it (I use the Expand Selection to Quotes plugin and just hit Ctrl') and hit AltQ to wrap. If you need to edit the string, select all the text and hit CtrlJ to join the lines back into one. When you're done editing, you can rewrap.
In my preferences I have
"word_wrap": "true",
"wrap_width": 0
so that even a single long string will automatically wrap like so:
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With