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 3877272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:28:43+00:00 2026-05-19T22:28:43+00:00

How to temporary show a snapshot of a file, while hiding comments and blank

  • 0

How to temporary show a snapshot of a file, while hiding comments and blank line?

The purpose would be to get a catch of a C++ function (for example), in a dense page formating.

A manner to do that is to use the global command to filter out lines of comments

:g!/\/\/

but then the syntax highlighting and move controls disappear.

The folding feature of Vim is a way to do the job, but it does only reduce several consecutive comments to a single line that is visually intrusive.

Anyway, folding is still useful to hide long C-like comments, for example with:

:set foldmethod=marker
:set foldmarker=/*,*/

But I did not manage to easily fold both C (/…/) and C++ (//…) comments in a single command.

The ideal trick would:

  • hide (not just fold in a single line) comments and blank lines,
  • perhaps indicate hidden lines with a character on the first column,
  • handle both C and C++ comments,
  • while preserving the syntax highlighting,
  • and, ideally, the ability to browse the code,
  • permits an easy revert to come back to the “commented” view.

So as to transform the following code:

/** Let say hello
* and do not forget anybody
*/
void hello( int arg )
{
  // OMG an hello world!
  std::cout << "hello" << std::endl;

} // where is the world?

Into the following buffer:

void hello( int arg )
{
  std::cout << "hello" << std::endl;
}
  • 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-05-19T22:28:44+00:00Added an answer on May 19, 2026 at 10:28 pm

    All comments can be removed from the source with the following command:
    :%s/\/\*\_.\{-}\*\/\n\{,1}\|^\s*\/\/.*\n\|\s*\/\/.*//

    This can then be undone with the u command, assuming no other actions are there to be undone.

    Since vi regexes can be extremely cryptic, below is an explanation of each part. The entire regex is split into three parts separated by an OR operator (\|).

    \/\*\_.\{-}\*\/\n\{,1}
    This is to match block comments of the form /* ... */. It matches the string ‘/*’ (\/\*) followed by zero or more of any character, including new line, but matching as few as possible (\_.\{-}), followed by zero or one newline (\n\{,1}). The reason it matches zero or one new line is to handle both the case where there is code on the same line as the comment and the case when the comment is on a line by itself.

    ^\s*\/\/.*\n
    This is to match comments of the form //... where the comment is on a line by itself. It matches zero or more whitespace characters that start with the beginning of the line (^\s*) followed by the string ‘//’ (\/\/), then zero or more of any character (.*), ending with a new line (\n).

    \s*\/\/.*
    This matches comments of the form //... where the comment follows code. It matches any amount of whitespace (\s*) followed by the string // (\/\/) and then any number of characters that are not newline (.*).

    This is the best I can come up with at the moment, if I can think of a way to hide instead of delete the comments, I’ll update this post.

    Update:
    A possible way to simply “hide” the comments might be to color them the same as the background. This would render them invisible. However, I currently don’t know how feasible that idea might be or how well it would generalize. I don’t know enough about colors in vim to be able to write a script to accomplish this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a temporary table (or, say, a function which returns a table of
I'm creating some temporary files in the iPad simulator. To test my file creation,
I need a black temporary transparent box that must show something like Loading.... with
I have a few long term processes and temporary processes in Python. While shell
I have a SQL file with temporary tables creation, some load data infile, some
i am trying to save hello world with single quote in temporary file i
I want ProgressDialog to show while my code enables WiFi and connects to a
In certain situation users can send temporary files to my server. I would like
I have a gridview that i would like to show or hide a text
What's the best way to create a temporary variable inside a .phtml template while

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.