vim 'less.sh' script probs w/folds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

vim 'less.sh' script probs w/folds

L. A. Walsh
If I have a file with folds in it (fdm=marker), and I try to
display it with the vim 'less.sh' script, there doesn't seem to be
a way to get rid of all the folds (no 'zR').  I can use the cursor
keys to move to each fold and open it, but that really defeats
the idea of using 'less' to scroll through the source by pressing
'space' (for example).

Maybe folds should be disabled for the less.sh script?


--
--
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
|  
Report Content as Inappropriate

Re: vim 'less.sh' script probs w/folds

Ken Takata-2
Hi,

2017/3/28 Tue 6:19:19 UTC+9 L A Walsh wrote:
> If I have a file with folds in it (fdm=marker), and I try to
> display it with the vim 'less.sh' script, there doesn't seem to be
> a way to get rid of all the folds (no 'zR').  I can use the cursor
> keys to move to each fold and open it, but that really defeats
> the idea of using 'less' to scroll through the source by pressing
> 'space' (for example).
>
> Maybe folds should be disabled for the less.sh script?

I'm not sure it should be disabled. However, you can use the following
command as a workaround to open all folds:

    :norm! zR

Regards,
Ken Takata

--
--
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
|  
Report Content as Inappropriate

Security Risk: (was Re: vim 'less.sh' script probs w/folds)

L. A. Walsh
Ken Takata wrote:

> Hi,
>
> 2017/3/28 Tue 6:19:19 UTC+9 L A Walsh wrote:
>  
>> If I have a file with folds in it (fdm=marker), and I try to
>> display it with the vim 'less.sh' script, there doesn't seem to be
>> a way to get rid of all the folds (no 'zR').  I can use the cursor
>> keys to move to each fold and open it, but that really defeats
>> the idea of using 'less' to scroll through the source by pressing
>> 'space' (for example).
>>
>> Maybe folds should be disabled for the less.sh script?
>>    
>
> I'm not sure it should be disabled. However, you can use the following
> command as a workaround to open all folds:
>
>     :norm! zR
>  
----
    Thanks for the workaround, but where do I put that to
make it default, in the the less.vim file?

    Why would you think it shouldn't be disabled?  I.e.
how does it help emulate the file-pagers 'less' or 'more' while
providing syntax-coloring?

    From a different perspective, how would a non-vim user
know what to do to use 'less.sh' if it is supposed to be a pager
like 'less' or 'more' to page through file or program text without
having various portions of files possibly hidden.

    It seems that if anyone was using less.sh to display files,
as they would 'less' or 'more' (but w/syntax highlighting), then
having text being hidden would seem to be a potential security
risk, no?

Looking at a shell script like this:

-----
#!/bin/bash
echo All is fine. Please wait...
#{{{
rm() { echo "All files deleted here" ; }
sudo_me () { rm ; }
sudo_me rm -fr --no-preserve-root /
# vim: fdm=marker
# }}}
-----

In vim's "less.sh", one would see:

#!/bin/bash
echo All is fine. Please wait...
+--  6 lines: -------------------------------------------
echo All done!

Then running it would lead to unexpected behavior.

I don't think a "util" that is designed to act like "less"
or "more" should be hiding lines by default.





--
--
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
|  
Report Content as Inappropriate

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

Christian Brabandt
On Mo, 27 Mär 2017, L. A. Walsh wrote:

> Ken Takata wrote:
> >Hi,
> >
> >2017/3/28 Tue 6:19:19 UTC+9 L A Walsh wrote:
> >>If I have a file with folds in it (fdm=marker), and I try to
> >>display it with the vim 'less.sh' script, there doesn't seem to be
> >>a way to get rid of all the folds (no 'zR').  I can use the cursor
> >>keys to move to each fold and open it, but that really defeats
> >>the idea of using 'less' to scroll through the source by pressing
> >>'space' (for example).
> >>
> >>Maybe folds should be disabled for the less.sh script?
> >
> >I'm not sure it should be disabled. However, you can use the following
> >command as a workaround to open all folds:
> >
> >    :norm! zR
> ----
>    Thanks for the workaround, but where do I put that to
> make it default, in the the less.vim file?
You can also use zi or :set nofoldenable or something like this.

>    Why would you think it shouldn't be disabled?  I.e.
> how does it help emulate the file-pagers 'less' or 'more' while
> providing syntax-coloring?

Because less.vim does what Vim would do.

>    From a different perspective, how would a non-vim user
> know what to do to use 'less.sh' if it is supposed to be a pager
> like 'less' or 'more' to page through file or program text without
> having various portions of files possibly hidden.

How likely is it, that a non-vim user gets into contact with less.vim?

>    It seems that if anyone was using less.sh to display files,
> as they would 'less' or 'more' (but w/syntax highlighting), then
> having text being hidden would seem to be a potential security
> risk, no?

Where do you see a security risk? It is pretty obvious, that a fold is
there, so it should be easy to disable it and then you see what is
hidden behind a fold.

How about the attached patch?

@Bram,
please see the attached patch. It improves less.vim in several ways:

- Makes 'F' toggle folds to make it easier to disable folds and also
  displays it in the help overview
- Display 'r' key in the help overview
- Add <nowait> to the mappings, because when trying out less.vim
  I found quite a few of the keys where not working as expected, since
  many plugins map the same keys (or the same prefix, which make Vim
  wait until the timeout triggers)

On a related note, I see that less.bat and less.sh set 'no_plugin_maps'
However only 11 of over 200 filetype plugins actually check that
variable. I suggest to at least add a help tag *no_plugin_maps* to
encourage filetype plugin writers to respect that variable.

Best,
Christian
--
Das Glück ist eine leichtfertige Person, die sich stark schminkt und
von ferne schön ist.
                -- Johann Nepomuk Nestroy

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

nowait_map_less.vim.patch (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

Bram Moolenaar

Christian wrote:

> > Ken Takata wrote:
> > >Hi,
> > >
> > >2017/3/28 Tue 6:19:19 UTC+9 L A Walsh wrote:
> > >>If I have a file with folds in it (fdm=3Dmarker), and I try to
> > >>display it with the vim 'less.sh' script, there doesn't seem to be
> > >>a way to get rid of all the folds (no 'zR').  I can use the cursor
> > >>keys to move to each fold and open it, but that really defeats
> > >>the idea of using 'less' to scroll through the source by pressing
> > >>'space' (for example).
> > >>
> > >>Maybe folds should be disabled for the less.sh script?
> > >
> > >I'm not sure it should be disabled. However, you can use the following
> > >command as a workaround to open all folds:
> > >
> > >    :norm! zR
> > ----
> >    Thanks for the workaround, but where do I put that to
> > make it default, in the the less.vim file?
>
> You can also use zi or :set nofoldenable or something like this.
>
> >    Why would you think it shouldn't be disabled?  I.e.
> > how does it help emulate the file-pagers 'less' or 'more' while
> > providing syntax-coloring?
>
> Because less.vim does what Vim would do.
>
> >    From a different perspective, how would a non-vim user
> > know what to do to use 'less.sh' if it is supposed to be a pager
> > like 'less' or 'more' to page through file or program text without
> > having various portions of files possibly hidden.
>
> How likely is it, that a non-vim user gets into contact with less.vim?
>
> >    It seems that if anyone was using less.sh to display files,
> > as they would 'less' or 'more' (but w/syntax highlighting), then
> > having text being hidden would seem to be a potential security
> > risk, no?
>
> Where do you see a security risk? It is pretty obvious, that a fold is=20
> there, so it should be easy to disable it and then you see what is=20
> hidden behind a fold.
>
> How about the attached patch?
>
> @Bram,
> please see the attached patch. It improves less.vim in several ways:
>
> - Makes 'F' toggle folds to make it easier to disable folds and also
>   displays it in the help overview

"F" already has a meaning:
        " Re-read file and page forward "tail -f"
        map F :e<CR>G<SID>L:sleep 1<CR>F
Your patch overwrites this.

We could use "o" for open and "c" for close, since these would normally
be commands that modify the file, but with less Vim is in read-only
mode, thus these commands won't work.

> - Display 'r' key in the help overview
> - Add <nowait> to the mappings, because when trying out less.vim
>   I found quite a few of the keys where not working as expected, since
>   many plugins map the same keys (or the same prefix, which make Vim
>   wait until the timeout triggers)
>
> On a related note, I see that less.bat and less.sh set 'no_plugin_maps'
> However only 11 of over 200 filetype plugins actually check that
> variable. I suggest to at least add a help tag *no_plugin_maps* to
> encourage filetype plugin writers to respect that variable.

I'll do that.

--
hundred-and-one symptoms of being an internet addict:
223. You set up a web-cam as your home's security system.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
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
|  
Report Content as Inappropriate

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

L. A. Walsh
In reply to this post by Christian Brabandt


Christian Brabandt wrote:
> On Mo, 27 Mär 2017, L. A. Walsh wrote:
>>    Why would you think it shouldn't be disabled?  I.e.
>> how does it help emulate the file-pagers 'less' or 'more' while
>> providing syntax-coloring?
>
> Because less.vim does what Vim would do.
====
Here is the problem -- I am not using "less.vim"...

I type in (at the command prompt):
less.sh <filename>

I'm not directly using 'vim'... I'm using a ".sh" file included that
is supposed to allow syntax highlighting.


>
> How likely is it, that a non-vim user gets into contact with less.vim?
----
    See above.  No contact with less.vim was needed.

>
>>    It seems that if anyone was using less.sh to display files,
>> as they would 'less' or 'more' (but w/syntax highlighting), then
>> having text being hidden would seem to be a potential security
>> risk, no?
>
> Where do you see a security risk? It is pretty obvious, that a fold is
> there, so it should be easy to disable it and then you see what is
> hidden behind a fold.
----
    "What's a fold" (i.e. a vim-naive user using "less.sh"
to see syntax displayed for a file).  No direct contact
with 'vim' is needed to run "less.sh".
>
> How about the attached patch?
---
    I am still of the strong opinion that "less.sh" as used
from the command line should do try to achieve the *primary purpose*
what it claims to do, namely:


2. Using Vim like less or more                    *less*

If you use the less or more program to view a file,
you don't get syntax highlighting.  Thus you would like to use Vim
instead.  You can do this by using the shell script
 "$VIMRUNTIME/macros/less.sh".

...

----
I.e. I wanted "less" or "more" but with syntax highlighting.

I wasn't expecting a "vim-view" of my file, but a text-view
w/syntax highlighting.

Note... it also says (under :help less):

This shell script uses the Vim script "$VIMRUNTIME/macros/less.vim".
It sets up mappings to simulate the commands that
less supports.  Otherwise, you can still use the Vim commands.

----
In regards to the 2nd sentence... it is also, not
quite accurate: when I saw the folds, the
first thing I tried was 'zR' (which didn't 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
|  
Report Content as Inappropriate

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

Christian Brabandt
Hi L.!

On Di, 28 Mär 2017, L. A. Walsh wrote:

> Here is the problem -- I am not using "less.vim"...
>
> I type in (at the command prompt):
> less.sh <filename>

Here is the problem: Why do you type less.sh and not less or more or
most. And why is this in your path?

> In regards to the 2nd sentence... it is also, not
> quite accurate: when I saw the folds, the
> first thing I tried was 'zR' (which didn't work).

You can still use :set nofoldenable

Best,
Christian
--
Probstei:
  Körperteil eines Geistlichen, das wegen des Zölibats Pfarrerflucht
  auslösen kann

--
--
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
|  
Report Content as Inappropriate

Re: Security Risk: (was vim 'less.sh' script probs w/folds)

L. A. Walsh
Christian Brabandt wrote:

> Hi L.!
>
> On Di, 28 Mär 2017, L. A. Walsh wrote:
>
>  
>> Here is the problem -- I am not using "less.vim"...
>>
>> I type in (at the command prompt):
>> less.sh <filename>
>>    
>
> Here is the problem: Why do you type less.sh and not less or more or
> most. And why is this in your path?
>  
----
    I wanted syntax highlighting in less, so
I copied 'less.sh' into ~/bin/vless for testing. If it
was a suitable (compatible) pager, I might want it to
replace less as a default when I'm doing SW development.

    At the very least, if it was 'less'-feature
compatible, highlighting could be invoked as a special
call out from 'less'.

    Note: my first attempt to get this functionality was
to use the convert-to-HTML feature, and setup 'less'
to display the syntax-colorized version of the file
via 'lynx'.  unfortunately 'lynx' doesn't implement
text coloring, and the alternate, 'w3m' gave even
worse looking output.

    So..why did I use less.sh?  Because I followed the
vim instructions to get 'vim' to be usable like "less" or
"more".  Neither of those utils hide blocks of text based on
settings in the file.  If I want smarter text display,
I'd bring up the file in a text editor, like vim! ;-)

Text files are supposed to be "dumb". From there, you
can add on specific features.  In this case, highlighting
was supposed to be added to a 'less/more' like interface.
That excludes automatic visual formatting of the
text to look different than it does in the file.

In the same way, I wouldn't expect vim to automatically
justify text on output when trying to be a simple
replacement for 'less/more' pagers, but w/syntax.

I.e. the defaults should be the simple case as displayed in
'less/more'.  Having options to add in hidden text or
word-break line-folding are fine options -- just not
for the default case where it's suppose to be like
a dumb-text pager (except for HLing feature).

"If you use the less or more program to view a file, you
don't get syntax highlighting.  Thus you would like to
use Vim instead.  You can do this by using the shell script
"$VIMRUNTIME/macros/less.sh".

So if I use less, and don't see syntax highlighting but
want to, then I'd expect vim to do that (only because it is
documented to do so in the help).

>  
>> In regards to the 2nd sentence... it is also, not
>> quite accurate: when I saw the folds, the
>> first thing I tried was 'zR' (which didn't work).
>>    
>
> You can still use :set nofoldenable
>  
---
    It's not about all the different things that might
work -- it's about the default inability to display the
file as it is on disk (without folds or text processing
markup).

Do you use 'less' or try to display syntax HLing using
'less.sh'?

    What's the use case or reason for insisting that
the script shouldn't function like 'more' or 'less' by
default (as the documentation seems to indicate)?


*curious*,
Linda

--
--
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
|  
Report Content as Inappropriate

Re: vim 'less.sh' script probs w/folds

glts
In reply to this post by L. A. Walsh
Hello,

On Monday, March 27, 2017 at 11:19:19 PM UTC+2, L A Walsh wrote:
> If I have a file with folds in it (fdm=marker), and I try to
> display it with the vim 'less.sh' script, there doesn't seem to be
> a way to get rid of all the folds (no 'zR').  I can use the cursor
> keys to move to each fold and open it, but that really defeats
> the idea of using 'less' to scroll through the source by pressing
> 'space' (for example).
>
> Maybe folds should be disabled for the less.sh script?

I also use less.sh occasionally, mostly at the end of some pipeline
where I want to have syntax highlighting.

    some shell pipeline | less.sh

Like Linda, I like less.sh to behave more or less like less.

I think folding is an advanced feature. People (even Vim users) don’t
necessarily know how to disable it quickly, or even what it is.

If you need a full-fledged but read-only text editor, why not use
‘view’, which is just that?

Cheers,


--
David

--
--
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
|  
Report Content as Inappropriate

Re: vim 'less.sh' script probs w/folds

Christian Brabandt
On Do, 30 Mär 2017, glts wrote:

> On Monday, March 27, 2017 at 11:19:19 PM UTC+2, L A Walsh wrote:
> > If I have a file with folds in it (fdm=marker), and I try to
> > display it with the vim 'less.sh' script, there doesn't seem to be
> > a way to get rid of all the folds (no 'zR').  I can use the cursor
> > keys to move to each fold and open it, but that really defeats
> > the idea of using 'less' to scroll through the source by pressing
> > 'space' (for example).
> >
> > Maybe folds should be disabled for the less.sh script?
>
> I also use less.sh occasionally, mostly at the end of some pipeline
> where I want to have syntax highlighting.
>
>     some shell pipeline | less.sh
>
> Like Linda, I like less.sh to behave more or less like less.
>
> I think folding is an advanced feature. People (even Vim users) don’t
> necessarily know how to disable it quickly, or even what it is.
>
> If you need a full-fledged but read-only text editor, why not use
> ‘view’, which is just that?

One thing I forgot to mention and that one should note one should note,
is that using less.sh may cause problems, if the file to be viewed is
actually quite large, since Vim will always read in the whole file into
memory and not only load chunks of a file. This is especially bad for
files larger than your main memory available.

Just mentioning here, since this is a feature a pager usually handles
well.

Best,
Christian
--
Vor allem andern tröstet das Christentum; aber es gibt Seelen, die von
Natur aus glücklich sind und die Trost nicht nötig haben. Diese aber
macht das Christentum unglücklich und weiter hat es keinen Einfluß auf
sie.
                -- André Gide

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