Skip to content
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

Merged
merged 13 commits into from
Jul 31, 2018
Merged

Format text lines #2274

merged 13 commits into from
Jul 31, 2018

Conversation

ricksladkey
Copy link
Collaborator

Changes

  • Rename functions associated with = formatting to be named FormatCodeLines
  • Add a new common operation to format text lines called FormatTextLines
  • Add gq and gw operations to format text lines in visual mode
  • Add gqgq, gqq, gwgw and gww operations to format text lines in normal mode
  • Add textwidth setting defaulting to 0
  • Add comments setting defaulting to line comments in C, C++, C#, F#, Java, Javascript, Python, Lisp, Shell

Fixes

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

  • The formatoptions variable is not implemented
  • None of the comment specification flags in comments are implemented
  • Tabs in the leader are properly accounted for but tabs in the text are not
  • All the lines being formatted in one operation must have the same leader
  • gw is currently the same as gq, i.e. it doesn't preserve the caret position

@ricksladkey
Copy link
Collaborator Author

I'm already using this every day! So nice...

let autoIndent = _localSettings.AutoIndent
let textWidth =
if _localSettings.TextWidth = 0 then
79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 79?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@jaredpar jaredpar left a 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.

@ricksladkey
Copy link
Collaborator Author

Moved the magic number to VimConstants with a comment.

@jaredpar jaredpar merged commit 1a5bee0 into VsVim:master Jul 31, 2018
@ricksladkey ricksladkey deleted the format-text branch July 31, 2018 04:10
@mqudsi mqudsi mentioned this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants