LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux 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

Reply
 
LinkBack Search this Thread
Old 07-22-2006, 06:27 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Rep: Reputation: 30
Vim plugin for hiding block comments


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?
 
Old 07-22-2006, 07:18 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,500

Rep: Reputation: 285Reputation: 285Reputation: 285
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.
 
Old 07-24-2006, 07:12 PM   #3
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
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?
 
Old 07-24-2006, 10:12 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,500

Rep: Reputation: 285Reputation: 285Reputation: 285
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).
 
Old 07-24-2006, 10:28 PM   #5
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,500

Rep: Reputation: 285Reputation: 285Reputation: 285
Here's another way...

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

Now all block comments are folded, automatically.
 
Old 07-27-2006, 02:15 PM   #6
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
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 '{,}'?
 
Old 07-27-2006, 02:34 PM   #7
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,500

Rep: Reputation: 285Reputation: 285Reputation: 285
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.
 
Old 07-27-2006, 04:26 PM   #8
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 244

Original Poster
Rep: Reputation: 30
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
 
  


Reply

Tags
block, code, comment, plugin, vim


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 05:41 AM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-17-2006 11:54 PM
VIM insert before a visual block... pld Linux - Software 0 06-22-2005 11:36 AM
vim - comments formatting alexLinux Programming 0 12-24-2003 04:22 PM
vim plugin - taglist doesn't work correctly milod Programming 0 07-19-2003 08:13 AM


All times are GMT -5. The time now is 04: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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration