Alternate indentation display in Vim
I came across this question: https://softwareengineering.stackexchange.com/questions/87077/how-can-a-code-editor-effectively-hint-at-code-nesting-level-without-using-inde and thought that Vim migh开发者_如何转开发t be able to do something similar as well with a plugin.
I believe the indentation level could be indicated with the a sign (icon in GUI, text with highlighting in term). The piece I'm not sure about is displaying the lines without indentation. Does anyone know, is it possible and/or how you would do it?
This question is not whether or not displaying indentation levels in this manner is desirable; but how to accomplish it in Vim.
You could use the conceal
feature that is new in 7.3.
Here is a function that does roughly what the article is describing (for spaces; accounting for tabs instead would be a fairly trivial addition):
function! IndentationHeatMap()
set conceallevel=1
for i in range(1,9)
let indentation = repeat(" ", &sts * i)
exe 'syntax match NonText "^' . indentation . '" conceal cchar=' . i
endfor
endfunction
A solution closer to what you are requesting might use conceal
to hide all leading whitespace with
syntax match NonText "^\s\+" conceal
and then use signs
to provide the indicators based on custom calculations.
Note: NonText
in these syntax commands is an arbitrary highlight group.
Take a look at these plugins: Indent Guides and IndentHL Both have screenshots.
精彩评论