-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format text lines #2274
Format text lines #2274
Conversation
I'm already using this every day! So nice... |
Src/VimCore/CommonOperations.fs
Outdated
let autoIndent = _localSettings.AutoIndent | ||
let textWidth = | ||
if _localSettings.TextWidth = 0 then | ||
79 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 79?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the vim documentation says it uses if textwidth
is zero!
If the 'textwidth' option is 0, the formatted length is the screen width (with a maximum width of 79).
I guess the idea is that it wraps at 80 columns but makes a concession for terminals that "double-wrap" the line if it is exactly 80.
Also, from this documentation you can see that I did not limit the width to the screen width, which doesn't seem to be a reasonable setting to use with Visual Studio where the user has virtually no control over the width of the window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a comment for the magic number 79? Other than that this looks great.
Moved the magic number to |
Changes
=
formatting to be namedFormatCodeLines
FormatTextLines
gq
andgw
operations to format text lines in visual modegqgq
,gqq
,gwgw
andgww
operations to format text lines in normal modetextwidth
setting defaulting to 0comments
setting defaulting to line comments in C, C++, C#, F#, Java, Javascript, Python, Lisp, ShellFixes
Discussion
This is a "bare-bones" implementation of formatting text lines that omits many of the more esoteric vim features but adds the crucially missing capability to intuitively reformat comments in the most used programming languages. Subsequent more ambitious PRs can address the missing functionality.
Limitations
formatoptions
variable is not implementedcomments
are implementedgw
is currently the same asgq
, i.e. it doesn't preserve the caret position