Sunday, March 6, 2011

Re: using the help system in split screen mode

Reply to message «Re: using the help system in split screen mode»,
sent 20:03:40 06 March 2011, Sunday
by Chris Jones:

> setl bt= | execute "vert help " a:s | execute ':redraw!'
> ..
> setl bt= | execute "help " a:s | execute ':redraw!'
Just a minor fix: you don't need a second `execute' here as well as space after
the `help':

setl bt= | execute "help" a:s | redraw!
(or, if you want to add space explicitely: `execute "help ".a:s')

Original message:
> On Mon, Feb 28, 2011 at 08:51:03PM EST, Ben Schmidt wrote:
>
> [..]
>
> Sorry for delay.. had more urgent issues to address..
>
> >> The suggested pipe 'setl bt= | help' does indeed override Vim's miserly
> >> behavior relative to help windows..
> >>
> >> Why?
> >
> > Because Vim identifies help windows by the buftype, so if you clear it,
> > Vim no longer thinks it is a help window, so doesn't reuse it.
>
> What I find a little odd is that 'setl bt= | help' clears &bt .. and
> only then creates the window (the help command).. and yet it works.
>
> > I would advise against this, as it has other side effects, e.g. using
> >
> > :help in the existing window will not reuse it as desired, but open a
> >
> > new window. A few other help-window-specific behaviours will also not
> > work on the old help window if you do this.
> >
> >> Another quick question.. in Vimscript, what is the natural idiom to
> >> code:
> >>
> >> if count == 0; do proc_0; fi
> >> if count == 1; do proc_1; fi
> >> if count> 1; do proc_n; fi
> >>
> >> Otherwise, is there a decent tutorial on how to write functions in
> >> Vim..?
> >
> > I'm not sure Vimscript has any natural idioms! You will probably get a
> > whole bunch of opinions on how best to do anything. Quite possibly the
> > best idiom is what seems most natural to you.
>
> Hm. I doubt that... :-)
>
> Anyway.. here goes:
>
> ------------------------------------------------------------------------
> if exists("loaded_HH")
> finish
> endif
> let loaded_HH = 1
>
> function! MyHelp(s)
> " how many help windows already open in this tab?
> let hc=len(filter(range(1, winnr('$')), 'getbufvar(winbufnr(v:val),
> "&ft")==#"help"'))
>
> " No help window yet.. open a new tab and display the help
> if hc == 0
> tab help | execute "help " a:s | execute ':redraw!'
> endif
>
> " One help window already.. let's do a vert split & display the help
> if hc == 1
> setl bt= | execute "vert help " a:s | execute ':redraw!'
> endif
>
> " Two or more..? split the current pane horizontally... etc.
> if hc > 1
> setl bt= | execute "help " a:s | execute ':redraw!'
> endif
> endfunction
>
> command! -nargs=* HH call MyHelp(<q-args>)
> ------------------------------------------------------------------------
>
> So ':HH subject' Does almost what I need, but for one little problem:
>
> The ':redraw' command meant to skip the 'Press Enter to continue'
> message at the bottom of the screen saving me the trouble of having to
> hit Enter.. only works when creating the new tab page - (hc = 0). For
> the other two pipes that cause the screen to be split (hc ≥ 0) it does
> not.
>
> Another odd thing I noticed.. the syntax highlighting is badly off for
> these two lines:
>
> setl bt= | execute "vert help " a:s | execute ':redraw!'
> ..
> setl bt= | execute "help " a:s | execute ':redraw!'
>
> I switched to the default colorscheme to make sure.. and everything
> East of the first pipe does not have the right colors: 'execute' is
> white on a black background (same as variables) and the rest of the line
> is dark blue (same as comments).
>
> Maybe the suntax file does not like the 'setl bt=' with no value
> specified..?
>
> Anyway.. if you or anyone else has any suggestions as to how I should
> have written the above in nice idiomatic Vimscript.. rather than what
> seems most natural to me...
>
> Oh.. and what would be the right way to emulate hitting the Enter key to
> skip those pesky 'Press Enter..' messages..? Something that actually
> works and might be a little less cryptic than ':redraw!'..?
>
> Thanks,
>
> cj

No comments:

Post a Comment