2016-12-16 17:43 GMT+03:00 Gary Johnson <garyjohn@spocom.com>:
> 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 vim_use+unsubscribe@googlegroups.com.
> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Friday, December 16, 2016
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment