When you have a text file with long lines, what is the way to reformat them to a certain width, while
not jumbling them up together?
Generally, what I'm looking for is this in Vim,
(to be done on every line)
V
gq
j
with textwidth
set in advance.
ALT
+ CMD
+ q
on OS X will hard wrap a line to whatever ruler column you have set. See Andrew's answer for the ruler settings.
ALT
+ q
works on Windows, and according to this comment, it works on Linux too.
Wrapping comment lines
According to the comments, Sublime Text doesn't wrap comments very well, such as
/*
* Blah blah blah blah blah blah blah blah blah
*/
// Blah blah blah blah blah blah blah blah blah
The plugin Sublime Wrap Plus can be used to wrap these. However, it doesn't seem to work well if you Select All your file, it seems to work best if you select only the comment lines that you want to wrap. (Tested in Sublime Text 3, not 2).
The Edit → Wrap menu has a ton of options for hard wrapping paragraphs at different line lengths.
"Wrap Paragraph at Ruler" will use whatever setting you have for rulers, set like so in your user preferences (see https://stackoverflow.com/a/11319526/120898):
// Adds a single vertical ruler at line 80
"rulers": [80],
Or you can set a temporary ruler with View → Ruler.
Yep, this is possible once you enable vintage
mode:
Preferences > Settings -- Default
- Remove
Vintage
from the ignored_packages
section
Vintage mode makes Sublime act like VIM, for the most part. Now you can use the key combo you mentioned above.
Sublime will reindent code for you and usually does a pretty good job. You can find the option in the menu if you go to Edit → Line → Reindent.
Or You can have a custom key binding setup in Sublime so You can reindent code with shortcut.
To do that, just add the following line to Preferences → Key Bindings – User.
{"keys": ["alt+shift+r"], "command": "reindent" , "args": {"single_line": false}}