4

I'm displaying a file contents by using :pedit …the-file-path…, to then call popup_setoptions(…the-ID…,#{firstline:anumber}) in order to scroll the popup and highlight/show the desired part of the file.

There's however one problem — the folds are closed by default and thus they hide the file contents… How to open them?

What I've tried is a exe ':'.pupid.'windo norm! zi' however the command fails upfront with and 'Invalid range` error. The pupid is being obtained via popup_findpreview() and is correct.

4
  • 2
    you can possibly use :pedit +set\ nofoldenable <file>. – Christian Brabandt Sep 4 '20 at 12:47
  • 1
    Can confirm that :pedit +set\ nofoldenable <file> works too; IMO, it should be the accepted answer. – user938271 Sep 4 '20 at 13:49
  • @ChristianBrabandt Would you post it as an answer please? – filbranden Sep 4 '20 at 19:21
  • 1
    @filbranden thanks done – Christian Brabandt Sep 7 '20 at 8:36
5

What I've tried is a exe ':'.pupid.'windo norm! zi' however the command fails upfront with and 'Invalid range` error. The pupid is being obtained via popup_findpreview() and is correct.

That's because popup_findpreview() gives you a window ID, but the range passed to :windo expects window numbers:

:[range]windo {cmd} Execute {cmd} in each window or if [range] is given only in windows for which the window number lies in the [range]. It works like doing this: >

Try to use win_execute() instead of :windo:

call win_execute(pupid, 'norm! zi')

The latter is better anyway, because it has fewer side-effects.

1
  • 1
    It works! I've had to use zR instead of zi, however. – Mooncer Sep 4 '20 at 12:46
2

If you look at the help for the :pedit command, you will see this:

                                                    :ped :pedit
:ped[it][!] [++opt] [+cmd] {file}
            Edit {file} in the preview window.  The preview window is
            opened like with :ptag.  The current window and cursor
            position isn't changed.  Useful example: 
                    :pedit +/fputc /usr/include/stdio.h

Note that you can use the +cmd command to execute an additional command when opening the preview window. In your case, you can open the file and disallowing folding by using this command then:

:pedit +setl\ nofoldenable <file>

Not, that you need to escape the whitespace between the :setl and the actual option value. You can probably also add an additional command to scroll to the required line, e.g. something like this:

:pedit +setl\ nofoldenable|44 <file>

To open <file>, disable folding in that window and jump to line 44.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.