Fwd: Indentation Vertical Lines

291 views
Skip to first unread message

Andy Christianson

unread,
May 21, 2010, 10:01:07 AM5/21/10
to v...@vim.org
Is it possible to get Vim to display vertical lines that help to track indentation? I can't think of the best way to describe it (or search for it), but you can see it in this screenshot (http://www.rutherfurd.net/files/jedit/jedit_ss3.jpg).


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

Brian L. Matthews

unread,
May 21, 2010, 11:40:38 AM5/21/10
to vim...@googlegroups.com
On 5/21/10 7:01 AM, Andy Christianson wrote:
Is it possible to get Vim to display vertical lines that help to track indentation? I can't think of the best way to describe it (or search for it), but you can see it in this screenshot (http://www.rutherfurd.net/files/jedit/jedit_ss3.jpg).

Try:

set listchars=tab:\|-                      
set list

and help 'listchars' and help 'list' for more information.

Brian

Benjamin R. Haskell

unread,
May 21, 2010, 12:02:12 PM5/21/10
to vim...@googlegroups.com
On Fri, 21 May 2010, Andy Christianson wrote:

> Is it possible to get Vim to display vertical lines that help to track
> indentation? I can't think of the best way to describe it (or search
> for it), but you can see it in this screenshot
> (http://www.rutherfurd.net/files/jedit/jedit_ss3.jpg).

If you always use tabs to indent, you might try playing with 'listchars'
(= 'lcs'). The results of:

:set lcs=tab:|·

shows up pretty close to your screenshot for me. The difference is that
a tab shows up as |··· (instead of ···· with a vertical line
interleaved)

Instead of '|' (VERTICAL LINE (aka 'pipe')), if your preferred font
supports it, I like U+2502 '│' (BOX DRAWINGS LIGHT VERTICAL).
(Vertically-aligned │'s are flush with one another. Compare:)
│││ |||
│││ |||
│││ |||

:set lcs=tab:│·

At work, where I pay more attention to tabs, I use:

:set lcs=tab:»·

(At home, I always use tabs, so I find that distracting)

In all cases, I also use the 'trail:·' suboption, but see :help
'listchars' for more. You also need the 'list' option active.

--
Best,
Ben

Benjamin R. Haskell

unread,
May 21, 2010, 12:05:10 PM5/21/10
to vim...@googlegroups.com
On Fri, 21 May 2010, Benjamin R. Haskell wrote:

> [...] The results of:
>
> :set lcs=tab:|·

As Brian's faster answer reminded me, you need to escape the '|'
character:

:set lcs=tab:\|·

Benjamin R. Haskell

unread,
May 21, 2010, 12:07:01 PM5/21/10
to vim...@googlegroups.com
On Fri, 21 May 2010, Benjamin R. Haskell wrote:

> [...]you might try playing with 'listchars'. The results of:
>
> :set lcs=tab:|·

As Brian's faster answer reminded me, you need to escape the '|'
character:

:set lcs=tab:\|·

Tony Mechelynck

unread,
Jul 4, 2010, 4:24:13 AM7/4/10
to vim...@googlegroups.com, Andy Christianson
On 21/05/10 16:01, Andy Christianson wrote:
> Is it possible to get Vim to display vertical lines that help to track
> indentation? I can't think of the best way to describe it (or search for
> it), but you can see it in this screenshot
> (http://www.rutherfurd.net/files/jedit/jedit_ss3.jpg).

In addition to what was said about 'list' and 'listchars', to track
indentation you could also use the 'cursorcolumn' option, see

:help 'cursorcolumn'
:help 'cursorline'
:help hl-CursorColumn
:help hl-CursorLine

Personally I use

set cuc cul

in my vimrc, and

hi CursorColumn term=underline cterm=underline guibg=#F4F4F4
hi! link CursorLine CursorColumn

in my homemade colorscheme (a very light grey in the GUI so as to be
visible but not too distracting on a white field).


Best regards,
Tony.
--
The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but "That's funny ..."
-- Isaac Asimov

cnc...@gmail.com

unread,
Jul 4, 2010, 11:35:41 PM7/4/10
to vim...@googlegroups.com
"set listchars=tab:\|\ " (| and <sp>) really works fine when i use <tab> to indent files, but is there a way to show | chars when i use <sp> to indent program, especially when writing python?

Tony Mechelynck

unread,
Jul 5, 2010, 11:07:35 AM7/5/10
to vim...@googlegroups.com, cnc...@gmail.com

Spaces are spaces: Vim won't show them differently (except end-of-line
spaces with trail:- in 'listchars').

If you set 'cursorcolumn' on, the cursor column will have a distinctive
highlight, so you'll be able to see (by moving the cursor to the first
nonblank in a line) whether your indented lines line up the way they should.


Best regards,
Tony.
--
7:30, Channel 5: The Bionic Dog (Action/Adventure)
The Bionic Dog gets a hormonal short-circuit and violates the
Mann Act with an interstate Greyhound bus.

Vlad Irnov

unread,
Jul 5, 2010, 10:50:17 PM7/5/10
to vim_use
You can use syntax highlighting to highlight leading indents
differently.
See this script
http://www.vim.org/scripts/script.php?script_id=1800
and screenshots here
http://viming.blogspot.com/2007/02/indent-level-highlighting.html

The script is for tabs but it's easy to modify it for spaces.
Something like this:

^^^^^ ~/.vim/after/syntax/python.vim ^^^^^^^
syn match indLev1 /^ \{4}/ contains=ALL
hi indLev1 guibg=gray100

syn match indLev2 /^ \{8}/ contains=ALL
hi indLev2 guibg=gray96

syn match indLev3 /^ \{12}/ contains=ALL
hi indLev3 guibg=gray93

syn match indLev4 /^ \{16}/ contains=ALL
hi indLev4 guibg=gray90

syn match indLev5 /^ \{20}/ contains=ALL
hi indLev5 guibg=gray87

syn match indLev6 /^ \{24}/ contains=ALL
hi indLev6 guibg=gray84

syn match indLev7 /^ \{28}/ contains=ALL
hi indLev7 guibg=gray81
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Obviously, the colors have to be adjusted for each color scheme.
It's probably easier to use two or three alternating colors.

Vlad Irnov

unread,
Jul 6, 2010, 9:32:31 PM7/6/10
to vim_use
On Jul 4, 11:35 pm, "cncy...@gmail.com" <cncy...@gmail.com> wrote:
Here is another indent level syntax highlighting script.
It creates vertical lines, kind of like in jEdit screenshot in the
first post.
You only need to configure one hi group.

" Highlight vertical column of spaces for each indent level.
" Only works when indenting with spaces (:set et).
hi indGuide guibg=gray90
for i in range(1,10)
exec 'syn match indGuide /^ \{'.i*(&ts).'}/hs=e-'.(&ts-1).',he=e-'.
(&ts-1).' contains=ALL'
" alternative column placement
"exec 'syn match indGuide /^ \{'.i*(&ts).'}/hs=e contains=ALL'
endfor

Benjamin R. Haskell

unread,
Jul 7, 2010, 12:10:43 AM7/7/10
to vim...@googlegroups.com

With a Vim that has the 'conceal' feature:

" if shiftwidth = 3
:syntax LeadSpace match=/\(^\( \{3}\)*\)\@<=\zs \ze \{2}/ conceal cchar=│
" if shiftwidth = 4
:syntax LeadSpace match=/\(^\( \{4}\)*\)\@<=\zs \ze \{3}/ conceal cchar=│
:set conceallevel=1

That last char is Ux2502 (^V u 2 5 0 2): │ BOX DRAWINGS LIGHT VERTICAL
(For me, that makes consecutive vertical lines seamless.)
Some other possibly-useful cchar choices: │┃┆┇┊┋║ ▉▊▋▌▍▎▏▐░▒▓

The fact that the current line isn't 'conceal'ed is a bit off-putting in
this case, but see if you like it.

I found the following looked better (w/ &term='rxvt-unicode256'):

:highlight Conceal cterm=NONE ctermfg=250 ctermbg=NONE

--
Best,
Ben

Thomas Adam

unread,
Jul 7, 2010, 4:57:44 AM7/7/10
to vim...@googlegroups.com, v...@vim.org
On 21 May 2010 15:01, Andy Christianson <andy.chr...@gmail.com> wrote:
> Is it possible to get Vim to display vertical lines that help to track
> indentation? I can't think of the best way to describe it (or search for
> it), but you can see it in this screenshot
> (http://www.rutherfurd.net/files/jedit/jedit_ss3.jpg).

I use Charles Campbell's SeeTab.vim plugin to do this.

-- Thomas Adam

Reply all
Reply to author
Forward
0 new messages