Question about listchars

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about listchars

Jeff Lanzarotta
Hello,

I have the following in my vimrc,

--------
" This shows spaces and tabs characters. Visual Whitespace.
set listchars=tab:»·,trail:·
set list
--------

That all work well and good, but I would like to disable this display
of visual white space temporarily, do something, and then reset it back
to what I had. Is there a way to do this?

Peace,

-Jeff





-Jeff
Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Tim Chase-2
> " This shows spaces and tabs characters. Visual Whitespace.
> set listchars=tab:»·,trail:·
> set list
> --------
>
> That all work well and good, but I would like to disable this
> display of visual white space temporarily, do something, and
> then reset it back to what I had. Is there a way to do this?

Well, there are a number of possible solutions.  The 'listchars'
setting only allows for showing trailing whitespace.  If this is
what you're looking for, you can do something like

        set listchars+=trail:_

do your thing, and then

        set listchars-=trail:_

to undo it.

If you want to visualize all your whitespace, you can do it with

1) search highlighting (to get cleared on your next search):

        :set hls
        /\s

and then optionally reset with

        :set nohls

or

        :noh


2) match highlighting (to optionally be used in complement to
search highlighting):

        :match SpellBad /\s/

and then reset with

        :match NONE

3) or you can do it by substituting all of your white-space with
some visual character:

        :%s/\s/#/g

and then just undoing with "u" as usual.

Just a few ideas...

-tkc



Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Marius Roets
In reply to this post by Jeff Lanzarotta
On 10/19/06, Jeff Lanzarotta <[hidden email]> wrote:

> Hello,
>
> I have the following in my vimrc,
>
> --------
> " This shows spaces and tabs characters. Visual Whitespace.
> set listchars=tab:»·,trail:·
> set list
> --------
>
> That all work well and good, but I would like to disable this display
> of visual white space temporarily, do something, and then reset it back
> to what I had. Is there a way to do this?
>
> Peace,
How about this in your .vimrc
nmap <F5> :set invlist<cr>
imap <F5> <esc>:set invlist<cr>a

and then F5 would toggle list on and off.

HTH
Marius
Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Bill McCarthy
In reply to this post by Jeff Lanzarotta
On Thu 19-Oct-06 10:59am -0600, Jeff Lanzarotta wrote:

> I have the following in my vimrc,
>
> --------
> " This shows spaces and tabs characters. Visual Whitespace.
> set listchars=tab:»·,trail:·
> set list
> --------
>
> That all work well and good, but I would like to disable this display
> of visual white space temporarily, do something, and then reset it back
> to what I had. Is there a way to do this?

You can toggle back and forth with:

    :se invlist

This can be placed in a map like this:

    nm <silent> <leader>l :se invlist list?<CR>

where "invlist" will toggle the 'list' option and "list?"
will display the new state.

For help on ":se {option}?" and ":se inv{option}" see:

    :h set-option

--
Best regards,
Bill

Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Karl Guertin
In reply to this post by Jeff Lanzarotta
On 10/19/06, Jeff Lanzarotta <[hidden email]> wrote:
> That all work well and good, but I would like to disable this display
> of visual white space temporarily, do something, and then reset it back
> to what I had. Is there a way to do this?

:map <silent> <Leader>l :set invlist<CR>

Then type \l when you want to toggle (<Leader> is \ by default).
Change the binding however you like, but invfoo inverts the foo
setting.
Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Jeff Lanzarotta
In reply to this post by Bill McCarthy
Thanks for all the suggestions. They helped out... If there a way to
check and see if the listchar is actually set or not?

In my script, I now turn off the display with 'set invlist list?', but
I do not want to turn it back on if it was not previously set...


--- Bill McCarthy <[hidden email]> wrote:

> On Thu 19-Oct-06 10:59am -0600, Jeff Lanzarotta wrote:
>
> > I have the following in my vimrc,
> >
> > --------
> > " This shows spaces and tabs characters. Visual Whitespace.
> > set listchars=tab:»·,trail:·
> > set list
> > --------
> >
> > That all work well and good, but I would like to disable this
> display
> > of visual white space temporarily, do something, and then reset it
> back
> > to what I had. Is there a way to do this?
>
> You can toggle back and forth with:
>
>     :se invlist
>
> This can be placed in a map like this:
>
>     nm <silent> <leader>l :se invlist list?<CR>
>
> where "invlist" will toggle the 'list' option and "list?"
> will display the new state.
>
> For help on ":se {option}?" and ":se inv{option}" see:
>
>     :h set-option
>
> --
> Best regards,
> Bill
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Tim Chase-2
> Thanks for all the suggestions. They helped out... If there a way to
> check and see if the listchar is actually set or not?
>
> In my script, I now turn off the display with 'set invlist list?', but
> I do not want to turn it back on if it was not previously set...


Well, you can use the common idiom

        let l:old_list = &list
        set nolist
        " do stuff
        let &list = l:old_list

which will allow you to temporarily disable the 'list' setting,
do stuff without it, and then restore it to whatever it was
previously...

-tim





       
Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Jeff Lanzarotta
Awesome. Thanks...

--- Tim Chase <[hidden email]> wrote:

> > Thanks for all the suggestions. They helped out... If there a way
> to
> > check and see if the listchar is actually set or not?
> >
> > In my script, I now turn off the display with 'set invlist list?',
> but
> > I do not want to turn it back on if it was not previously set...
>
>
> Well, you can use the common idiom
>
> let l:old_list = &list
> set nolist
> " do stuff
> let &list = l:old_list
>
> which will allow you to temporarily disable the 'list' setting,
> do stuff without it, and then restore it to whatever it was
> previously...
>
> -tim
>
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Steve Hall-3
In reply to this post by Jeff Lanzarotta
On Thu, 2006-10-19 at 08:59 -0700, Jeff Lanzarotta wrote:

>
> I have the following in my vimrc,
>
> --------
> " This shows spaces and tabs characters. Visual Whitespace.
> set listchars=tab:»·,trail:·
> set list
> --------
>
> That all work well and good, but I would like to disable this
> display of visual white space temporarily, do something, and then
> reset it back to what I had. Is there a way to do this?

I wrote a plugin that toggles "invisible" characters with F4:

  http://vim.sourceforge.net/scripts/script.php?script_id=363


--
Steve Hall  [ digitect dancingpaper com ]


Reply | Threaded
Open this post in threaded view
|

Re: Question about listchars

Jean-Rene David-2
In reply to this post by Jeff Lanzarotta
* Jeff Lanzarotta [2006.10.19 13:13]:
> If there a way to check and see if the listchar
> is actually set or not?

For options I change often, I use the following to
display its value in the statusline.

function! OptSet(opt, string)
   if(exists("a:opt") && expand(a:opt))
      return a:string
   else
      return ""
   endif
endfunction

Then put the following in the statusline:

set statusline=%<%f\%h%m%r%y%{OptSet(&ic,'[ic]')}[...]
                             ^^^^^^^^^^^^^^^^^^^^

So in this specific case, if 'ic' is set, I will
have '[ic]' in my status line.

I use that for 'ic' and 'ws' because I toggle them
quite ofen.

HTH,

--
JR