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

Comments autoformatted even without formatoptions 'c' flag #3746

Open
msuperdock opened this issue Dec 31, 2018 · 2 comments
Open

Comments autoformatted even without formatoptions 'c' flag #3746

msuperdock opened this issue Dec 31, 2018 · 2 comments

Comments

@msuperdock
Copy link

msuperdock commented Dec 31, 2018

Note: I also filed this as a neovim issue 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.

@brammool
Copy link
Contributor

brammool commented Dec 31, 2018 via email

@msuperdock
Copy link
Author

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.

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

No branches or pull requests

2 participants