What is the usual way to reformat paragraph in Sub

2019-03-17 21:51发布

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.

4条回答
干净又极端
2楼-- · 2019-03-17 22:35

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

查看更多
爷的心禁止访问
3楼-- · 2019-03-17 22:36

Yep, this is possible once you enable vintage mode:

  1. Preferences > Settings -- Default
  2. 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.

查看更多
We Are One
4楼-- · 2019-03-17 22:45

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}}
查看更多
该账号已被封号
5楼-- · 2019-03-17 22:47

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.

查看更多
登录 后发表回答