Thursday, December 22, 2016

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

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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: