Zerg Overmind
Zerg Overmind

Reputation: 1055

How to make vim with tree representation for indents, similliar to result of terminals "tree" command?

I'm looking for some way to connect indets into tree structure similliar to the one used by terminal tree command.
enter image description here

Something that interprets the indents in same way tree interprets file system.
Alternatively for sublime text or another text editor.

Edit: Apologies for the broadness of question, to specify what i wanna do is>
Rather then replacing the actuall text i just want it to interpet the indents into the tree structure while retaining the actuall file should retain it's indents.

Upvotes: 0

Views: 377

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172550

You've asked a broad question (and did not show any research effort so far), so I all I can do is answering it broadly as well (for Vim):

permanent change

For a permanent change of the actual text, all you need is :substitute. A start would be

:%substitute/    \ze\S/└── /

To make this more beautiful, another pass could turn into by comparing previous and current line; :substitute or :global can do this.

just visualization

If you don't want to actually manipulate the buffer contents, but just affect the visual appearance, :set list and the 'listchars' option come to mind. Unfortunately, though this can display spaces and tabs, it does so uniformly; i.e. you cannot just apply it to the "last" part of the indent. You have a chance to implement this with :help conceal; this can translate a (sequence of) character(s) to a single (different) character. This is based on syntax highlighting. You could define matches for fourth last space before non-whitespace and conceal that as , and third and second last space before non-whitespace and conceal as , for example.

or a hybrid

Another approach would be a combination: Use (easier) modification with :substitute, but undo this before writing (with :autocmd hooks into the BufWritePre and BufWritePost events). If this is purely for viewing, you could also simply :setlocal nomodifiable or :setlocal buftype=nowrite to disallow editing / saving.

Upvotes: 4

Related Questions