On 06-Apr-2011 12:54, Stephen Lee wrote:
> Hello
> 
> 
> I am trying to expand the command window a bit so that it becomes a
> simple option selector (I put "set cmdheight=5" in vimrc). I echo
> those options like:
> (they are longer than the window)
> 
> 1. Option 1 -- ..............Long
> Explanation.................................
> 2. Option 2 -- ..............Long
> Explanation.................................
> 3. Option 3 -- ..............Long
> Explanation.................................
> 4. Option 4 -- ..............Long
> Explanation.................................
> 5. Option 5 -- ..............Long
> Explanation.................................
> |<--                         ScrollBar                          -->|
> 
> 
> However I cannot make those options nowrap around the end of the line
> as it will be ugly like this:
> 
> 1. Option 1 -- ..............Long Explanation......................
> ............
> 2. Option 2 -- ..............Long Explanation......................
> ............
> 3. Option 3 -- ..............Long Explanation......................
> ............
> 4. Option 4 -- ..............Long Explanation......................
> ............
> 5. Option 5 -- ..............Long Explanation......................
> ............
> |<--                         ScrollBar                          -->|
> 
> 
> I see the scrollbar but cannot scroll as the lines wrap at the end.
> "echo" or "echohl" simply does not listen to "set nowrap" or "setlocal
> nowrap". I search a lot including manual and books but cannot find.
> 
> 
> I wonder if they follow some basic formatting settings:
> 
> When wrap-on:
> setlocal linebreak + breakat
> 
> When wrap-off:
> setlocal scrolloff=2
> setlocal sidescrolloff=2
> 
> 
> Could anyone tell me how to nowrap the echoes?
> 
> Thankyou

While the command window is a (special kind of) window, the output of :echo goes
to the command line and 'cmdheight' applies to the command line, too. Since
there is no window (and no buffer), settings like 'wrap' do not apply, and
there's no scrollbar.

If you don't want your long output to wrap, just :echo that many characters that
fit into a single line. Functions like strdisplaywidth() and the \%v regexp atom
will help you make the cut at the correct location, as the width depends on the
character (think unprintables like ^C, double-width Kanji and the dynamically
sized <Tab>), so a naive use of strlen() (which returns the number of bytes, not
the width) will only work for a very limited number of characters.

On the other hand, depending on your use case it may make more sense to actually
open a "scratch buffer" (:split bufname, then :setlocal buftype=nofile
bufhidden=wipe nobuflisted noswapfile), and use setline() instead of :echo to
display the contents. Many plugins use that approach.

-- regards, ingo
-- 
  -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
  --      http://vim.sourceforge.net/account/profile.php?user_id=9713    --

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui