how fold all comment line?

27 views
Skip to first unread message

王军

unread,
Nov 15, 2012, 2:05:33 AM11/15/12
to vim...@googlegroups.com

Hi everyone:

    I want to fold all line which are comment.

    eg.

    //aaaaaaaaaaaaaaaaaa

    //bbbbbbbbbbbbbbbbbb

    //cccccccccccccccccc

    //dddddddddddddddddd

 

    Can vim do this ?

 

Best

    Regards!

 

Chris Lott

unread,
Nov 15, 2012, 2:19:59 AM11/15/12
to vim...@googlegroups.com
On Wed, Nov 14, 2012 at 10:05 PM, 王军 <wangju...@gmail.com> wrote:
> Hi everyone:
>
> I want to fold all line which are comment.
>
> eg.
>
> //aaaaaaaaaaaaaaaaaa

Something like this?

set fdm=expr
set fde=getline(v:lnum)=~'^\s*\/\/\\\|^\s*$'?1:0

c
--
Chris Lott <ch...@chrislott.org>

王军

unread,
Nov 15, 2012, 4:33:09 AM11/15/12
to vim...@googlegroups.com
Hi
If do you said, only fold "//" which are at the front of line

So I modify ,and like " set fde=getline(v:lnum)=~'\s*\/\/\\\|^\s*$'?1:0"

Now it will fold "//" which at back of line.

Like this " a = b; //comment



-----邮件原件-----
发件人: vim...@googlegroups.com [mailto:vim...@googlegroups.com] 代表 Chris Lott
发送时间: 2012年11月15日 15:20
收件人: vim...@googlegroups.com
主题: Re: how fold all comment line?
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Christian Brabandt

unread,
Nov 15, 2012, 4:56:01 AM11/15/12
to vim...@googlegroups.com
(please don't top poste)
On Thu, November 15, 2012 10:33, 王军 wrote:
> Hi
> If do you said, only fold "//" which are at the front of line
>
> So I modify ,and like " set fde=getline(v:lnum)=~'\s*\/\/\\\|^\s*$'?1:0"

you could leave out the first \s*, it doesn't matter here.

> Now it will fold "//" which at back of line.
>
> Like this " a = b; //comment

You need to anchor your pattern to the beginning of the line, like this:
set fde=set fde=getline(v:lnum)=~'^\s*\/\/\\\|^\s*$'?1:0 fdm=expr fen

You should probably read an introduction to regular expressions, like
:h 27.4 and the following.

regards,
Christian

Reply all
Reply to author
Forward
0 new messages