Vim Tips Wiki
m (How to implement vertical lines showing tab groups.. moved to See the tabs in your file: Page moved by JohnBot to improve title)
(Remove html character entities)
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=460
 
|id=460
  +
|previous=459
|title=how to implement vertical lines showing tab groups..
 
  +
|next=461
|created=April 21, 2003 13:32
+
|created=April 21, 2003
 
|complexity=basic
 
|complexity=basic
 
|author=Robert (MetaCosm)
 
|author=Robert (MetaCosm)
 
|version=5.7
 
|version=5.7
 
|rating=90/38
 
|rating=90/38
  +
|category1=
|text=
 
  +
|category2=
When browsing the jEdit screenshots page, I saw a feature I wanted and didn't have in vim. It was a vertical line showing tab groups.
 
 
 
 
if (this) {
 
 
| if (that) {
 
 
| | do stuff;
 
 
| }
 
 
}
 
 
 
 
[http://www.jedit.org/index.php?page=screenshot&image=10 http://www.jedit.org/index.php?page=screenshot&image=10] <-- show a much better example that my little example did...
 
 
 
 
I was wondering how todo this in vim.. turns out it is simple
 
 
:set list
 
 
:set listchars=tab:\|\
 
 
 
 
:h listchars for help
 
 
 
 
 
 
Hope this helps you... join #vim on irc.freenode.net for all your vim help needs :)
 
 
}}
 
}}
 
When browsing the jEdit screenshots page, I saw a feature I wanted and didn't have in Vim. It was a vertical line showing the Tab characters.
   
  +
<pre>
== Comments ==
 
 
if (this) {
You could really use ANY char to do your vertical groups.... . and | tend to work very well
 
 
| if (that) {
 
| | do stuff;
 
| }
 
}
  +
</pre>
   
 
I was wondering how to do this in Vim. Turns out it is simple.
'''Anonymous'''
 
, April 21, 2003 13:35
 
----
 
highlight SpecialKey guifg=&lt;color&gt; ctermfg=&lt;color&gt; in order to tweak the colors
 
   
  +
<pre>
 
:set list
  +
:set listchars=tab:\|\<Space>
  +
</pre>
   
  +
==References==
'''Anonymous'''
 
  +
*{{help|'listchars'}}
, April 21, 2003 13:46
 
----
 
I missed the trailing space after the backslash. So for people who missed it too......read the line above as - set listchars+=backslash-pipe-backslash-space
 
   
 
==Comments==
Mohit Kalra
 
  +
In order to tweak the colors
, April 21, 2003 21:39
 
 
highlight SpecialKey guifg=<color> ctermfg=<color>
----
 
Good tip -- here's a function+command to facilitate use:
 
   
Usage: :SeeTab (toggles between normal and bar'd tabbing styles)
 
 
" SeeTab: toggles between showing tabs and using standard listchars
 
fu! SeeTab()
 
if !exists("g:SeeTabEnabled")
 
let g:SeeTabEnabled = 1
 
let g:SeeTab_list = &amp;list
 
let g:SeeTab_listchars = &amp;listchars
 
let regA = --AT--a
 
redir --AT--a
 
hi SpecialKey
 
redir END
 
let g:SeeTabSpecialKey = --AT--a
 
let --AT--a = regA
 
silent! hi SpecialKey guifg=black guibg=magenta ctermfg=black ctermbg=magenta
 
set list
 
set listchars=tab:\|\
 
else
 
let &amp;list = g:SeeTab_list
 
let &amp;listchars = &amp;listchars
 
silent! exe "hi ".substitute(g:SeeTabSpecialKey,'xxx','','e')
 
unlet g:SeeTabEnabled g:SeeTab_list g:SeeTab_listchars
 
endif
 
endfunc
 
com! -nargs=0 SeeTab :call SeeTab()
 
 
 
cec--AT--NgrOyphSon.gPsfAc.nMasa.gov
 
, April 22, 2003 8:07
 
 
----
 
----
 
Here's a function+command to facilitate use:
hey! but this wont work with expandtabs on!
 
i would rather have expand tabs on because otherwise, if i ship my source to someone else who has a different tabstop, then all my indenting will get all messed up and lines will go beyond 80 and wrap around and what not...
 
does anybody have a solution for this in an expand tabs scenario??
 
   
 
Usage: :SeeTab (toggles between normal and bar'd tabbing styles)
gowri.satyanarayana--AT--oracle.com
 
, April 23, 2003 0:32
 
----
 
Use syntax highlighting when expand tabs are on. Note the use of &amp;sw to get the current shiftwidth for the expanded tabs.
 
 
&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;
 
   
  +
<pre>
fu! SeeTab()
 
 
" SeeTab: toggles between showing tabs and using standard listchars
if !exists("g:SeeTabEnabled")
 
 
fu! SeeTab()
let g:SeeTabEnabled = 0
 
 
if !exists("g:SeeTabEnabled")
end
 
if g:SeeTabEnabled==0
+
let g:SeeTabEnabled = 1
 
let g:SeeTab_list = &list
syn match leadspace /^\s\+/ contains=syntab
 
 
let g:SeeTab_listchars = &listchars
exe "syn match syntab /\\s\\{" . &amp;sw . "}/hs=s,he=s+1 contained"
 
 
let regA = @a
hi syntab guibg=Grey
 
  +
redir @a
let g:SeeTabEnabled=1
 
 
hi SpecialKey
else
 
 
redir END
syn clear leadspace
 
 
let g:SeeTabSpecialKey = @a
syn clear syntab
 
 
let @a = regA
let g:SeeTabEnabled=0
 
 
silent! hi SpecialKey guifg=black guibg=magenta ctermfg=black ctermbg=magenta
end
 
 
set list
endfunc
 
 
set listchars=tab:\|\
  +
else
 
let &list = g:SeeTab_list
 
let &listchars = &listchars
 
silent! exe "hi ".substitute(g:SeeTabSpecialKey,'xxx','','e')
 
unlet g:SeeTabEnabled g:SeeTab_list g:SeeTab_listchars
  +
endif
 
endfunc
 
com! -nargs=0 SeeTab :call SeeTab()
 
com! -nargs=0 SeeTab :call SeeTab()
  +
</pre>
   
bphelan--AT--mathworks.co.uk
 
, April 24, 2003 2:11
 
 
----
 
----
 
Use syntax highlighting when expand tabs are on. Note the use of &sw to get the current shiftwidth for the expanded tabs.
Wow -- great comments on this tip. I am hoping to tie this wonderf comment together into a Script. Great work guys. The ability to work with expandtab is really wonderful!
 
   
  +
<pre>
 
fu! SeeTab()
 
if !exists("g:SeeTabEnabled")
 
let g:SeeTabEnabled = 0
  +
end
 
if g:SeeTabEnabled==0
 
syn match leadspace /^\s\+/ contains=syntab
 
exe "syn match syntab /\\s\\{" . &sw . "}/hs=s,he=s+1 contained"
 
hi syntab guibg=Grey
 
let g:SeeTabEnabled=1
  +
else
 
syn clear leadspace
 
syn clear syntab
 
let g:SeeTabEnabled=0
  +
end
 
endfunc
 
com! -nargs=0 SeeTab :call SeeTab()
  +
</pre>
   
Robert (MetaCosm)
 
, April 24, 2003 10:38
 
 
----
 
----
this is GR8! but one correction - expand tabs setting expands tabs according to the tabstop setting not shiftwidth - so in the SeeTab() function, replace &amp;sw by &amp;ts
+
One correction: expand tabs setting expands tabs according to the tabstop setting not shiftwidth - so in the SeeTab() function, replace &sw by &ts
 
gowri.satyanarayana--AT--oracle.com
 
, April 24, 2003 22:12
 
----
 
Gowri,
 
 
I've installed the script at
 
 
http://www.vim.org/scripts/script.php?script_id=627
 
 
with the change you suggested
 
 
bphelan--AT--mathworks.co.uk
 
, April 25, 2003 3:19
 
----
 
Hello!
 
 
OK, I've put my version, [/scripts/script.php?script_id=628 vimscript&#35;628]. It now handles both
 
expandtab on and off cases. Enjoy!
 
 
   
cec--AT--NgrOyphSon.gPsfAc.nMasa.gov
 
, April 25, 2003 14:11
 
 
----
 
----
  +
There are now two scripts for this:
/me claps -- nothing like a little good competition
 
  +
*{{script|id=627}}
  +
*{{script|id=628}}
   
'''Anonymous'''
 
, April 25, 2003 14:41
 
 
----
 
----
<!-- parsed by vimtips.py in 0.461881 seconds-->
 

Revision as of 08:44, 29 September 2008

Tip 460 Printable Monobook Previous Next

created April 21, 2003 · complexity basic · author Robert (MetaCosm) · version 5.7


When browsing the jEdit screenshots page, I saw a feature I wanted and didn't have in Vim. It was a vertical line showing the Tab characters.

if (this) {
| if (that) {
| | do stuff;
| }
}

I was wondering how to do this in Vim. Turns out it is simple.

:set list
:set listchars=tab:\|\<Space>

References

Comments

In order to tweak the colors

highlight SpecialKey guifg=<color> ctermfg=<color>

Here's a function+command to facilitate use:

Usage: :SeeTab (toggles between normal and bar'd tabbing styles)

" SeeTab: toggles between showing tabs and using standard listchars
fu! SeeTab()
  if !exists("g:SeeTabEnabled")
    let g:SeeTabEnabled = 1
    let g:SeeTab_list = &list
    let g:SeeTab_listchars = &listchars
    let regA = @a
    redir @a
    hi SpecialKey
    redir END
    let g:SeeTabSpecialKey = @a
    let @a = regA
    silent! hi SpecialKey guifg=black guibg=magenta ctermfg=black ctermbg=magenta
    set list
    set listchars=tab:\|\
  else
    let &list = g:SeeTab_list
    let &listchars = &listchars
    silent! exe "hi ".substitute(g:SeeTabSpecialKey,'xxx','','e')
    unlet g:SeeTabEnabled g:SeeTab_list g:SeeTab_listchars
  endif
endfunc
com! -nargs=0 SeeTab :call SeeTab()

Use syntax highlighting when expand tabs are on. Note the use of &sw to get the current shiftwidth for the expanded tabs.

fu! SeeTab()
  if !exists("g:SeeTabEnabled")
    let g:SeeTabEnabled = 0
  end
  if g:SeeTabEnabled==0
    syn match leadspace /^\s\+/ contains=syntab
    exe "syn match syntab /\\s\\{" . &sw . "}/hs=s,he=s+1 contained"
    hi syntab guibg=Grey
    let g:SeeTabEnabled=1
  else
    syn clear leadspace
    syn clear syntab
    let g:SeeTabEnabled=0
  end
endfunc
com! -nargs=0 SeeTab :call SeeTab()

One correction: expand tabs setting expands tabs according to the tabstop setting not shiftwidth - so in the SeeTab() function, replace &sw by &ts


There are now two scripts for this: