1

I have a LaTeX file opened in Vim. While paragraph formatting using gq} command, it wraps the comment line also. I am using a recent installation of Windows Subsystem for Linux and Ubuntu 24.04 and Vim 9.1 with all default settings.

My file:

\section{one} % %This is comment % This is my text in multiple lines. 

After gq}, it is giving an output as below

\section{one} % %This is comment % This is my text in multiple lines. 

However, I want the comment not to be wrapped. The desired output is

\section{one} % %This is comment % This is my text in multiple lines. 

I have tried several things like setting text width, nowrap, syntax off, etc. Kindly help with setting that will work in Vim. Interestingly, another machine (Redhat 8.4 and Vim 8.0) and the Vim formatting is working as desired.

6
  • Welcome to Vi and Vim! Are you using some kind of plugin for LaTeX editing? Have you read :help gq? Please edit to include the values of the options mentioned there, i.e. 'formatexpr', 'formatprg' and 'formatoptions'. Thank you. I guess the answer will be to :set formatoptions with something from :help fo-table. Commented Aug 27 at 7:56
  • 2
    Btw, I can't reproduce in vim --clean with :set filetype=latex. I get your desired output. You may want to double-check filetype detection is on and works correctly. Anyway, we'll likely need more information to reproduce your issue. Commented Aug 27 at 7:58
  • 1
    Thanks for the prompt response. Not using any plugin except the default ones. formatexpr= is blank, formatprg= is also blank, formatoptions=tcq. Tried :help gq but is bit complex to me. File type default was plaintex and is changed to latex. Still, the problem persists. By the way; this is a recent installation on Windows (WSL) Ubuntu 24.04 and VIM91. All default settings. Interestingly, I checked in another machine (redhat 8.4 and vim80) and the vim formatting is working as desired. Commented Aug 27 at 13:33
  • 1
    Thanks for the reply. Prefer to edit your question and put the additional information there. All relevant information should be in the question. Whatever causes this must be in your Vim 9.1 configuration, you may find this post helpful. Commented Aug 27 at 13:47
  • 2
    Thank you. vim -u NONE -U NONE -N file.tex solves the problem temporarily. However, needs to find out which configuration/plugin is causing the behavior. Commented Aug 27 at 17:09

1 Answer 1

0

I suppose the 'comments' option for plaintex or tex file type is not correct.

It should be:

set comments=sO:%\ -,mO:%\ \ ,eO:%%,:% 

The following commands could help you to discover which plugin has modified its default value:

:verbose set comments 
4
  • Thank you. The suggested set comments=sO:%\ -,mO:%\ \ ,eO:%%,:% is not solving the problem. The command :verbose set comments give the following result: comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:- Commented Aug 30 at 6:18
  • Thanks for the feedback. The value of comments is odd. I'll try to figure out what could set it like that. Is the verbose command not given you any indication of the script that changed the option?. Do you confirm that after restoring it to the proposed value for the tex buffer the gq} still behave wrong? Commented Aug 30 at 8:15
  • The value you have seems to be the default like ftplugin/tex.vim didn't ran. Could you tell us what is the result of :verbose set define when a tex buffer is loaded? Commented Aug 30 at 14:21
  • Did you solved your issue? How can we help you further? Commented Sep 6 at 5:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.