How to fold or hide the comment in vimrc file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to fold or hide the comment in vimrc file?

Zhe Lee
I want to fold or hide the comment in the vimrc file.
I Google it and find mainly the 2 solution below but none of them worked.


syn match comment "\v(^\s*\".*\n)+" fold

set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'


My Vimrc file is like this, when I enter the 2 commands above nothing happens.

```
if g:atCompany
    " set tags+=D:/Ruchee/Files/code/self/ci/tags
    " set tags+=D:/Ruchee/Files/code/self/laravel/tags
    " set tags+=D:/Ruchee/Files/code/self/sf/tags
else
```

So how to hide the comments?

-----------
Another question plz, how to edit the code format in this edit box? It's terriable that I can't post code here.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Nikolay Aleksandrovich Pavlov
2016-12-16 5:41 GMT+03:00 Zhe Lee <[hidden email]>:

> I want to fold or hide the comment in the vimrc file.
> I Google it and find mainly the 2 solution below but none of them worked.
>
>
> syn match comment "\v(^\s*\".*\n)+" fold
>
> set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
>
>
> My Vimrc file is like this, when I enter the 2 commands above nothing happens.

First solution is incomplete (and probably will work only if you
disable syntax highlighting or modify syntax/vim.vim file, not sure),
second solution is incorrect: while it clearly was supposed to set
`&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
`getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
transformed into `s` (backslash needs to be escaped) and `"` starting
a comment (needs to be escaped too). In addition to this it is using
:set setting global values alongside with local while it should use
:setlocal to set only local values. Proper second variant is

    let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
    setlocal foldmethod=expr

First method lacks `foldmethod` setting.

>
> ```
> if g:atCompany
>     " set tags+=D:/Ruchee/Files/code/self/ci/tags
>     " set tags+=D:/Ruchee/Files/code/self/laravel/tags
>     " set tags+=D:/Ruchee/Files/code/self/sf/tags
> else
> ```
>
> So how to hide the comments?
>
> -----------
> Another question plz, how to edit the code format in this edit box? It's terriable that I can't post code here.
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Gary Johnson-4
On 2016-12-16, Nikolay Aleksandrovich Pavlov wrote:

> 2016-12-16 5:41 GMT+03:00 Zhe Lee
> > I want to fold or hide the comment in the vimrc file.
> > I Google it and find mainly the 2 solution below but none of them worked.
> >
> >
> > syn match comment "\v(^\s*\".*\n)+" fold
> >
> > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> >
> >
> > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
>
> First solution is incomplete (and probably will work only if you
> disable syntax highlighting or modify syntax/vim.vim file, not sure),
> second solution is incorrect: while it clearly was supposed to set
> `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> transformed into `s` (backslash needs to be escaped) and `"` starting
> a comment (needs to be escaped too). In addition to this it is using
> :set setting global values alongside with local while it should use
> :setlocal to set only local values. Proper second variant is
>
>     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')

Setting 'foldexpr' doesn't have to be that complicated.  Simply
fixing the escaping of the backslash and the double-quote will fix
the problem.

    setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'

Regards,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Nikolay Aleksandrovich Pavlov
2016-12-16 17:43 GMT+03:00 Gary Johnson <[hidden email]>:

> On 2016-12-16, Nikolay Aleksandrovich Pavlov wrote:
>> 2016-12-16 5:41 GMT+03:00 Zhe Lee
>> > I want to fold or hide the comment in the vimrc file.
>> > I Google it and find mainly the 2 solution below but none of them worked.
>> >
>> >
>> > syn match comment "\v(^\s*\".*\n)+" fold
>> >
>> > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
>> >
>> >
>> > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
>>
>> First solution is incomplete (and probably will work only if you
>> disable syntax highlighting or modify syntax/vim.vim file, not sure),
>> second solution is incorrect: while it clearly was supposed to set
>> `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
>> `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
>> transformed into `s` (backslash needs to be escaped) and `"` starting
>> a comment (needs to be escaped too). In addition to this it is using
>> :set setting global values alongside with local while it should use
>> :setlocal to set only local values. Proper second variant is
>>
>>     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
>
> Setting 'foldexpr' doesn't have to be that complicated.  Simply
> fixing the escaping of the backslash and the double-quote will fix
> the problem.
>
>     setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'

Do not use :set* for more or less complex string options, it is too
easy to make a mistake. It is more complicated then using :let: when
you use :let you simply create a string with necessary contents,
without caring about escaping specifically used for :set. Knowing how
to write a string literal is useful in many places, including `:let
&l:…`, and you also may employ your knowledge of YAML, JSON, C, etc
string escapes here (string literals of different languages have lots
of things in common). Knowing how to escape a string for :set* is
useful only for escaping strings for :set, and I hardly need this
knowledge even for writing modelines (the only place where you can’t
use :let syntax).

>
> Regards,
> Gary
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Zhe Lee
In reply to this post by Gary Johnson-4
On Friday, December 16, 2016 at 10:42:07 PM UTC+8, Gary Johnson wrote:

> On 2016-12-16, Nikolay Aleksandrovich Pavlov wrote:
> > 2016-12-16 5:41 GMT+03:00 Zhe Lee
> > > I want to fold or hide the comment in the vimrc file.
> > > I Google it and find mainly the 2 solution below but none of them worked.
> > >
> > >
> > > syn match comment "\v(^\s*\".*\n)+" fold
> > >
> > > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> > >
> > >
> > > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
> >
> > First solution is incomplete (and probably will work only if you
> > disable syntax highlighting or modify syntax/vim.vim file, not sure),
> > second solution is incorrect: while it clearly was supposed to set
> > `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> > `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> > transformed into `s` (backslash needs to be escaped) and `"` starting
> > a comment (needs to be escaped too). In addition to this it is using
> > :set setting global values alongside with local while it should use
> > :setlocal to set only local values. Proper second variant is
> >
> >     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
>
> Setting 'foldexpr' doesn't have to be that complicated.  Simply
> fixing the escaping of the backslash and the double-quote will fix
> the problem.
>
>     setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'
>
> Regards,
> Gary
I have tried this command `setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'` in my vimrc file should the line start with " be folded? Nothing happened in my vimrc file. Why is that ?

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Zhe Lee
In reply to this post by Nikolay Aleksandrovich Pavlov
On Friday, December 16, 2016 at 12:28:20 PM UTC+8, ZyX wrote:

> 2016-12-16 5:41 GMT+03:00 Zhe Lee <[hidden email]>:
> > I want to fold or hide the comment in the vimrc file.
> > I Google it and find mainly the 2 solution below but none of them worked.
> >
> >
> > syn match comment "\v(^\s*\".*\n)+" fold
> >
> > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> >
> >
> > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
>
> First solution is incomplete (and probably will work only if you
> disable syntax highlighting or modify syntax/vim.vim file, not sure),
> second solution is incorrect: while it clearly was supposed to set
> `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> transformed into `s` (backslash needs to be escaped) and `"` starting
> a comment (needs to be escaped too). In addition to this it is using
> :set setting global values alongside with local while it should use
> :setlocal to set only local values. Proper second variant is
>
>     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
>     setlocal foldmethod=expr
>
> First method lacks `foldmethod` setting.
>
> >
> > ```
> > if g:atCompany
> >     " set tags+=D:/Ruchee/Files/code/self/ci/tags
> >     " set tags+=D:/Ruchee/Files/code/self/laravel/tags
> >     " set tags+=D:/Ruchee/Files/code/self/sf/tags
> > else
> > ```
> >
> > So how to hide the comments?
> >
> > -----------
> > Another question plz, how to edit the code format in this edit box? It's terriable that I can't post code here.
> >
> > --
> > --
> > 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
> >
> > ---
> > You received this message because you are subscribed to the Google Groups "vim_use" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> > For more options, visit https://groups.google.com/d/optout.
tnx a lot for your reply. I am not quite familiar with the vim script syntax so I just paste your suggested command into the vim command line. Should the line start with " be folded? Nothing happened in my vimrc file.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Zhe Lee
In reply to this post by Nikolay Aleksandrovich Pavlov
On Friday, December 16, 2016 at 12:28:20 PM UTC+8, ZyX wrote:

> 2016-12-16 5:41 GMT+03:00 Zhe Lee <[hidden email]>:
> > I want to fold or hide the comment in the vimrc file.
> > I Google it and find mainly the 2 solution below but none of them worked.
> >
> >
> > syn match comment "\v(^\s*\".*\n)+" fold
> >
> > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> >
> >
> > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
>
> First solution is incomplete (and probably will work only if you
> disable syntax highlighting or modify syntax/vim.vim file, not sure),
> second solution is incorrect: while it clearly was supposed to set
> `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> transformed into `s` (backslash needs to be escaped) and `"` starting
> a comment (needs to be escaped too). In addition to this it is using
> :set setting global values alongside with local while it should use
> :setlocal to set only local values. Proper second variant is
>
>     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
>     setlocal foldmethod=expr
>
> First method lacks `foldmethod` setting.
>
> >
> > ```
> > if g:atCompany
> >     " set tags+=D:/Ruchee/Files/code/self/ci/tags
> >     " set tags+=D:/Ruchee/Files/code/self/laravel/tags
> >     " set tags+=D:/Ruchee/Files/code/self/sf/tags
> > else
> > ```
> >
> > So how to hide the comments?
> >
> > -----------
> > Another question plz, how to edit the code format in this edit box? It's terriable that I can't post code here.
> >
> > --
> > --
> > 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
> >
> > ---
> > You received this message because you are subscribed to the Google Groups "vim_use" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> > For more options, visit https://groups.google.com/d/optout.
You are one of the maintainer of the VAM? It is really amazing work!

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Gary Johnson-4
In reply to this post by Zhe Lee
On 2016-12-19, Zhe Lee wrote:

> On Friday, December 16, 2016 at 10:42:07 PM UTC+8, Gary Johnson wrote:
> > On 2016-12-16, Nikolay Aleksandrovich Pavlov wrote:
> > > 2016-12-16 5:41 GMT+03:00 Zhe Lee
> > > > I want to fold or hide the comment in the vimrc file.
> > > > I Google it and find mainly the 2 solution below but none of them worked.
> > > >
> > > >
> > > > syn match comment "\v(^\s*\".*\n)+" fold
> > > >
> > > > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> > > >
> > > >
> > > > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
> > >
> > > First solution is incomplete (and probably will work only if you
> > > disable syntax highlighting or modify syntax/vim.vim file, not sure),
> > > second solution is incorrect: while it clearly was supposed to set
> > > `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> > > `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> > > transformed into `s` (backslash needs to be escaped) and `"` starting
> > > a comment (needs to be escaped too). In addition to this it is using
> > > :set setting global values alongside with local while it should use
> > > :setlocal to set only local values. Proper second variant is
> > >
> > >     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
> >
> > Setting 'foldexpr' doesn't have to be that complicated.  Simply
> > fixing the escaping of the backslash and the double-quote will fix
> > the problem.
> >
> >     setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'
> >
> > Regards,
> > Gary
>
> I have tried this command `setlocal foldmethod=expr
> foldexpr=getline(v:lnum)=~'^\\s*\"'` in my vimrc file should the
> line start with " be folded? Nothing happened in my vimrc file.
> Why is that ?

It could be that you have 'foldlevel' set to a high value.  Try
typing

    zM

in normal mode or

    :set foldlevel=0

from the command line and see if those lines become folded.

Regards,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to fold or hide the comment in vimrc file?

Zhe Lee
On Tuesday, December 20, 2016 at 12:23:59 AM UTC+8, Gary Johnson wrote:

> On 2016-12-19, Zhe Lee wrote:
> > On Friday, December 16, 2016 at 10:42:07 PM UTC+8, Gary Johnson wrote:
> > > On 2016-12-16, Nikolay Aleksandrovich Pavlov wrote:
> > > > 2016-12-16 5:41 GMT+03:00 Zhe Lee
> > > > > I want to fold or hide the comment in the vimrc file.
> > > > > I Google it and find mainly the 2 solution below but none of them worked.
> > > > >
> > > > >
> > > > > syn match comment "\v(^\s*\".*\n)+" fold
> > > > >
> > > > > set foldmethod=expr foldexpr=getline(v:lnum)=~'^\s*"'
> > > > >
> > > > >
> > > > > My Vimrc file is like this, when I enter the 2 commands above nothing happens.
> > > >
> > > > First solution is incomplete (and probably will work only if you
> > > > disable syntax highlighting or modify syntax/vim.vim file, not sure),
> > > > second solution is incorrect: while it clearly was supposed to set
> > > > `&foldexpr` to `getline(v:lnum)=~'^\s*"'`, it really sets it to
> > > > `getline(v:lnum)=~'^s`: missing proper escaping results in `\s`
> > > > transformed into `s` (backslash needs to be escaped) and `"` starting
> > > > a comment (needs to be escaped too). In addition to this it is using
> > > > :set setting global values alongside with local while it should use
> > > > :setlocal to set only local values. Proper second variant is
> > > >
> > > >     let &l:foldexpr='getline(v:lnum)=~#'.string('^\s*"')
> > >
> > > Setting 'foldexpr' doesn't have to be that complicated.  Simply
> > > fixing the escaping of the backslash and the double-quote will fix
> > > the problem.
> > >
> > >     setlocal foldmethod=expr foldexpr=getline(v:lnum)=~'^\\s*\"'
> > >
> > > Regards,
> > > Gary
> >
> > I have tried this command `setlocal foldmethod=expr
> > foldexpr=getline(v:lnum)=~'^\\s*\"'` in my vimrc file should the
> > line start with " be folded? Nothing happened in my vimrc file.
> > Why is that ?
>
> It could be that you have 'foldlevel' set to a high value.  Try
> typing
>
>     zM
>
> in normal mode or
>
>     :set foldlevel=0
>
> from the command line and see if those lines become folded.
>
> Regards,
> Gary
Yeah, it worked ~ I haven't read the doc about the `fold` my bad, tnx ~

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.