Discussion:
how to display the leading spaces in vim
(too old to reply)
Bing
2008-09-28 01:48:22 UTC
Permalink
Hi all,
I am wondering if there is an easy way to display the leading
spaces in vim.
Using color to highlight these spaces is not what I want. Ideally I
want the
same effect for displaying the leading spaces as I currently have for
the trailing
spaces using
set list
set lcs=tab:». "show tabs
set lcs+=trail:. "show trailing spaces
For some people around me, the way I am currently using in vim as
above to
differentiate the tabs and spaces in Python code is not as good as the
way
they can do in Crimson Editor or Ulipad. The rationale is that it is
not that easy
to count the number of leading spaces when it is simply blank white
space compared
to in Crimson Editor or Ulipad you can make the leading spaces look
like dots.
This feature is also in the Visual Studio (Ctrl R and Ctrl W).

Many thanks in advance!

Bing
Tony Mechelynck
2008-09-28 23:30:08 UTC
Permalink
Post by Bing
Hi all,
I am wondering if there is an easy way to display the leading
spaces in vim.
Using color to highlight these spaces is not what I want. Ideally I
want the
same effect for displaying the leading spaces as I currently have for
the trailing
spaces using
set list
set lcs=tab:». "show tabs
set lcs+=trail:. "show trailing spaces
For some people around me, the way I am currently using in vim as
above to
differentiate the tabs and spaces in Python code is not as good as the
way
they can do in Crimson Editor or Ulipad. The rationale is that it is
not that easy
to count the number of leading spaces when it is simply blank white
space compared
to in Crimson Editor or Ulipad you can make the leading spaces look
like dots.
This feature is also in the Visual Studio (Ctrl R and Ctrl W).
Many thanks in advance!
Bing
Vim cannot display leading spaces the way 'listchars' displays trailing
spaces, ends-of-lines, etc.

I see two possibilities:
1) With 'list' on and 'listchars' including a non-blank "tab" part
(i.e., other than "tab:\ \ ") and a non-blank "nbsp" part, anything
displayed as blank is a space.
2) It is possible to change the background color for leading spaces, e.g.

:match Todo /^ \+/

I know you might not like either possibility, but I don't see anything else.

However, to count the number of leading spaces, you can use the
following: with 'laststatus' set to 2, hit ^ to get to the first
nonblank in the line; then you'll see near bottom right in which column
you are. The number of leading spaces is one more than that if there are
no hard tabs within the leading whitespace.


Best regards,
Tony.
--
Life is like an analogy
Teemu Likonen
2008-09-28 07:09:18 UTC
Permalink
I am wondering if there is an easy way to display the leading spaces
in vim. Using color to highlight these spaces is not what I want.
The rationale is that it is not that easy to count the number of
leading spaces when it is simply blank white space compared to in
Crimson Editor or Ulipad you can make the leading spaces look like
dots.
Unfortunately there is no way at all. Possible work-arounds:

In GVim you can highlight patterns with curly underline which makes it
a bit easier to count spaces. Curly underline is used in spell-checker
by default. Try this:

:match SpellBad /^\s\+/

Another work-around would be to display current line's indent as
a number in the statusline, for example. Function indent() returns
line's indent in spaces, starting from 0. This command prints it for the
current line:

:echo indent(line('.'))

But you have to move to cursor to that line, and since you have to do
this you might as well move the cursor to first non-blank character with
the "^" command and see the indent from the ruler (:set 'ruler').
John Beckett
2008-09-30 00:48:06 UTC
Permalink
Post by Bing
For some people around me, the way I am currently using in vim as
above to differentiate the tabs and spaces in Python code is not
as good as the way they can do in Crimson Editor or Ulipad.
You've had the news about Vim, but why do you have a mixture of tabs
and spaces in Python code? If you really must do that, wouldn't pylint
do a better job of checking the indents than you counting spaces?

If you need to occaasionally count the number of leading spaces on a
particular line, and Tony's advice doesn't suit, you could quite
easily map a key to display the required count. Ask if wanted.

John
Bing
2008-09-30 13:19:46 UTC
Permalink
Post by John Beckett
Post by Bing
For some people around me, the way I am currently using in vim as
above to differentiate the tabs and spaces in Python code is not
as good as the way they can do in Crimson Editor or Ulipad.
You've had the news about Vim, but why do you have a mixture of tabs
and spaces in Python code? If you really must do that, wouldn't pylint
do a better job of checking the indents than you counting spaces?
If you need to occaasionally count the number of leading spaces on a
particular line, and Tony's advice doesn't suit, you could quite
easily map a key to display the required count. Ask if wanted.
John
John,
You are definitely right. Whether the feature I am asking is
useful
or necessary is not important for me. I asked this question just
because
I want to show my friends that vim can easily be configured to have
the
features they like in other editors they are using now. But seems
it is a little disappointing for me that vim can not easily display
the leading spaces in the way other editors do.
Anyway, thank you, Tony and Teemu for input and suggestions.

Bing



It is just a little disappointing for me that vim seems
can not do this

Loading...