LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools Search this Thread
Old 07-22-2006, 07:27 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 237
Thanked: 0
Vim plugin for hiding block comments


[Log in to get rid of this advertisement]
I am looking for a vim plugin that could hide or shrink block comments. For example, a block comment would be something like this:

/* ------------------------------------------------------------------------------------------------
Function: void print(string s)
Descript: prints input string message to the standard output and if logging is enabled, writes the messages to the log file
Programmer: John Doe
Version: 0.0.1
Called By: int main(int argc, char* argv[])
Calls To:
Input: standard 128-key keyboard
Output: writes to similarity vector, color-frequencies array
Parameters:
Returns: true if there were no problems processing the images, false if there was a problem with the image dimensions.

0.0.1 06/14/2006 C.D.
Wrote the function
------------------------------------------------------------------------------------------------ */
void print(string s)
{
// code
}

I would like the plugin to make it look something like this:
/* ------------------------------------------------------------------------------------------------
void print(string s)
{

This feature is available in Kdevelop and some other text editors that will shrink your blocks of code/comments. It's really quite handy. I often have to use vim to program on the console and this would be very useful to have available.

Does anyone know of such a vim plugin?
sadarax is offline  
Tag This Post , , , ,
Reply With Quote
Old 07-22-2006, 08:18 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86, x86_64, PPC
Posts: 3,602
Blog Entries: 1
Thanked: 9
You don't need a plug-in, the feature is built-in. It's called folding, and folks have examples for folding comment blocks here.
macemoneta is offline     Reply With Quote
Old 07-24-2006, 08:12 PM   #3
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 237
Thanked: 0

Original Poster
Quote:
Originally Posted by macemoneta
You don't need a plug-in, the feature is built-in. It's called folding, and folks have examples for folding comment blocks here.
Wow, thanks a lot of the information. I have got the folding working very well. I have just one more question.

Currenty, I can fold anything I have my cursor over and cause all folds to re-open in the document. Is there a way to everything in the document with standard comment patterns and { } fold automatically with a key command?
sadarax is offline     Reply With Quote
Old 07-24-2006, 11:12 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86, x86_64, PPC
Posts: 3,602
Blog Entries: 1
Thanked: 9
You can map the folding to an unused key, using the ':map' command. You can, of course, predefine the commands in your vim profile (~/.vimrc and ~/.gvimrc).
macemoneta is offline     Reply With Quote
Old 07-24-2006, 11:28 PM   #5
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86, x86_64, PPC
Posts: 3,602
Blog Entries: 1
Thanked: 9
Here's another way...

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

Now all block comments are folded, automatically.
macemoneta is offline     Reply With Quote
Old 07-27-2006, 03:15 PM   #6
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 237
Thanked: 0

Original Poster
Quote:
Originally Posted by macemoneta
Here's another way...

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

Now all block comments are folded, automatically.
That is great, but is there a way to bind that to a key and not have it happen on startup? Also, can it be done for braces '{,}'?
sadarax is offline     Reply With Quote
Old 07-27-2006, 03:34 PM   #7
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86, x86_64, PPC
Posts: 3,602
Blog Entries: 1
Thanked: 9
Replace the open/close comment markers with braces in the foldermarker to have it work for them. You can use the foldexpr to define multiple folds.

You can bind a key to the 'zi' command, to alternately open close all folds. For example:

:map q zi

Google on "vim fold" will find many examples and creative uses.
macemoneta is offline     Reply With Quote
Old 07-27-2006, 05:26 PM   #8
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 237
Thanked: 0

Original Poster
Thanks again for the help. Sorry to keep bothering you but I still cannot get the last bit of functionality that I want.

So, thus far I have got vim to fold either fold all comments on startup, but not allow me to manually unfold or fold things individually (though I can toggle on/off for all folds). Here is my current setup if I want to have everything folded automatically:

:set foldmethod=marker
:set foldmarker=/*,*/
:map f v%zf " manually close a fold
:map F zD " manually open a fold
:map <F3> zi " toggle open/close folds
:map <F4> zn " open all folds

Now with these settings, I cannot manually fold individual things but not cause everything in the document to fold on key command. This is what I would like to do...

:set foldmethod=marker
:set foldmarker=/*,*/
:map f v%zf " manually close a fold
:map F zD " manually open a fold
:map <F3> zi " toggle open/close folds
:map <F4> zn " open all folds
sadarax is offline     Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"HOWTO Change Colour of Comments in VIM editor" manikantha Linux - General 2 04-12-2009 06:41 AM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-18-2006 12:54 AM
VIM insert before a visual block... pld Linux - Software 0 06-22-2005 12:36 PM
vim - comments formatting alexLinux Programming 0 12-24-2003 05:22 PM
vim plugin - taglist doesn't work correctly milod Programming 0 07-19-2003 09:13 AM


All times are GMT -5. The time now is 05:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration