Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:24:27+00:00 2026-06-12T13:24:27+00:00

I’m looking for a convenient way to fix comments where line lengths exceed a

  • 0

I’m looking for a convenient way to fix comments where line lengths exceed a certain number of characters in Vim. I’m fine with doing this manually with code, especially since it’s not that frequent, plus refactoring long lines is often language, or even code-style dependent, but with comments this is pure drudgery.

What happens is I often spot some issue in a comment, tweak one or two words and the line spills out of the, say, 80 character limit. I move the last word to the next line and then the next line spills, and so on. Does anyone know a way to do this automatically in Vim?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:24:28+00:00Added an answer on June 12, 2026 at 1:24 pm

    I would recommend putting the following into your vimrc if this is a regular issue:

    nnoremap <leader>f gqip
    

    This maps the leader f shortcut (f is for “format”) to format the comment (considered a paragraph after setting some formatoption flags) with gq which formats the comment to be the width of the currently set textwidth or tw option. You should set textwidth in your .vimrc with textwidth=80.

    Formatoptions is the other thing you should fiddle with, specifically in your case by adding the acq flags with formatoptions+=acq. Be careful to remove the t flag with formatoptions-=t because that will automatically wrap all of your code, not just recognized comments. After doing all this you should be able to hit f and format inside only the comment, irrespective of whether is is surrounded by blank lines.

    Here is the relevant info on formatoptions so you can make your own choices.

    t       Auto-wrap text using textwidth
    
    c       Auto-wrap comments using textwidth, inserting the current comment
        leader automatically.
    
    r       Automatically insert the current comment leader after hitting
        <Enter> in Insert mode.
    
    o       Automatically insert the current comment leader after hitting 'o' or
        'O' in Normal mode.
    
    q       Allow formatting of comments with "gq".
        Note that formatting will not change blank lines or lines containing
        only the comment leader.  A new paragraph starts after such a line,
        or when the comment leader changes.
    
    w       Trailing white space indicates a paragraph continues in the next line.
        A line that ends in a non-white character ends a paragraph.
    
    a       Automatic formatting of paragraphs.  Every time text is inserted or
        deleted the paragraph will be reformatted.  See |auto-format|.
        When the 'c' flag is present this only happens for recognized
        comments.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.