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
Comments autoformatted even without formatoptions 'c' flag #3746
Comments
Note: I originally filed this as a neovim issue
[here](neovim/neovim#9422). It was suggested
on the #neovim IRC channel to also post this here.
- Version: 8.1.146 (also affects neovim 0.3.1)
- Operating system/version: NixOS 18.09
- Terminal name/version: st-0.8.1
- `$TERM`: st-256color
### Steps to reproduce using `vim -u NONE`
```
vim -u NONE
:set fo=ta<cr>i% test<cr>% test
```
### Actual behaviour
On typing the second '%', autoformatting kicks in, and the two lines
are combined into one. The final result is a single line:
```
% test % test
```
### Expected behaviour
Since `:set comments` gives a string including ":%", I expect that
when I type the second '%', vim recognizes the second line as a
comment and does not combine the two lines into one, since
`formatoptions` does not include the `c` flag. My expected final
result is:
```
% test
% test
```
### Explanation
The documentation for `fo-table` says:
> With 't' and 'c' you can specify when Vim performs auto-wrapping:
> value action
> "" no automatic formatting (you can use "gq" for manual formatting)
> "t" automatic formatting of text, but not comments
> "c" automatic formatting for comments, but not text (good for C code)
> "tc" automatic formatting for text and comments
When we use `set fo=ca`, we get the nice behavior where no automatic
formatting is done outside of comments, but comments reflow
automatically. The documentation above leads me to expect the
symmetric behavior for `set fo=ta`, where no automatic formatting is
done within comments, but the rest of the text reflows automatically.
The example above shows that the behavior is not symmetric the way the
documentation suggests, unless I'm misunderstanding the documentation.
One reason I want to use `set fo=ta` is for editing Markdown files--if
it worked the way I expected, I could set the `comments` option so
that code blocks are considered as comments. Then I could get
automatic formatting in most of the file, yet avoid automatic
formatting within code blocks.
There two separate functions: Breaking a line when it gets too long, and
reformatting a paragraph whenever text is changed inside it.
Without the "c" flag the breaking of long text doesn't happen
in comments.
With the "c" flag paragraphs are only auto-formatted if they are
recognized as comments.
There currently is no way to specify that auto-formatting ONLY applies
to commengs. The current behavior was done because it seemd like the
most useful way (auto-formatting comments in a code file), but it is
inconsistent.
This would require a new flag, which would do the opposite of what "c"
does in "ca". I suppose we could use the capital "C" for that.
…--
From "know your smileys":
*<|:-) Santa Claus (Ho Ho Ho)
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
Thanks for the explanation--the behavior makes more sense to me now. I personally would like having an additional flag, but I think it would also be reasonable for you to decide that this use case isn't common enough to warrant adding more code. Maybe the fo-table documentation could be changed to make it more clear that there are two pieces of functionality at work here? I would be happy to draft a documentation change if you'd like. |
Note: I also filed this as a neovim issue here.
$TERM
: st-256colorSteps to reproduce using
vim -u NONE
Actual behaviour
On typing the second '%', autoformatting kicks in, and the two lines are combined into one. The final result is a single line:
Expected behaviour
Since
:set comments
gives a string including ":%", I expect that when I type the second '%', vim recognizes the second line as a comment and does not combine the two lines into one, sinceformatoptions
does not include thec
flag. My expected final result is:Explanation
The documentation for
fo-table
says:When we use
set fo=ca
, we get the nice behavior where no automatic formatting is done outside of comments, but comments reflow automatically. The documentation above leads me to expect the symmetric behavior forset fo=ta
, where no automatic formatting is done within comments, but the rest of the text reflows automatically. The example above shows that the behavior is not symmetric the way the documentation suggests, unless I'm misunderstanding the documentation.One reason I want to use
set fo=ta
is for editing Markdown files--if it worked the way I expected, I could set thecomments
option so that code blocks are considered as comments. Then I could get automatic formatting in most of the file, yet avoid automatic formatting within code blocks.The text was updated successfully, but these errors were encountered: