Skip to content

Commit 8accb09

Browse files
committed
Make tree style (|+~ or arrows) configurable
1 parent 867de91 commit 8accb09

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

doc/NERD_tree.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@ NERD tree. These options should be set in your vimrc.
642642
|'NERDTreeWinSize'| Sets the window size when the NERD tree is
643643
opened.
644644

645+
|'NERDTreeDirArrows'| Tells the NERD tree to use arrows instead of
646+
+ ~ chars when displaying directories.
647+
645648
------------------------------------------------------------------------------
646649
3.2. Customisation details *NERDTreeOptionDetails*
647650

@@ -921,6 +924,19 @@ Default: 31.
921924

922925
This option is used to change the size of the NERD tree when it is loaded.
923926

927+
------------------------------------------------------------------------------
928+
*'NERDTreeDirArrows'*
929+
Values: 0 or 1
930+
Default: 0.
931+
932+
This option is used to change the default look of directory nodes displayed in
933+
the tree. When set to 0 it shows old-school bars (|), + and ~ chars. If set to
934+
1 it shows right and down arrows. Use one of the follow lines to set this
935+
option: >
936+
let NERDTreeDirArrows=0
937+
let NERDTreeDirArrows=1
938+
<
939+
924940
==============================================================================
925941
4. The NERD tree API *NERDTreeAPI*
926942

plugin/NERD_tree.vim

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ call s:initVariable("g:NERDTreeShowFiles", 1)
6565
call s:initVariable("g:NERDTreeShowHidden", 0)
6666
call s:initVariable("g:NERDTreeShowLineNumbers", 0)
6767
call s:initVariable("g:NERDTreeSortDirs", 1)
68+
call s:initVariable("g:NERDTreeDirArrows", 0)
6869

6970
if !exists("g:NERDTreeSortOrder")
7071
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
@@ -147,7 +148,7 @@ endif
147148
let s:NERDTreeBufName = 'NERD_tree_'
148149

149150
let s:tree_wid = 2
150-
let s:tree_markup_reg = '^[ `|▾▸]*[\-+~ ]*'
151+
let s:tree_markup_reg = '^[ `|]*[\-+~▾▸ ]*'
151152
let s:tree_up_dir_line = '.. (up a dir)'
152153

153154
"the number to add to the nerd tree buffer name to make the buf name unique
@@ -1313,20 +1314,50 @@ function! s:TreeFileNode._renderToString(depth, drawText, vertMap, isLastChild)
13131314
"get all the leading spaces and vertical tree parts for this line
13141315
if a:depth > 1
13151316
for j in a:vertMap[0:-2]
1316-
let treeParts = treeParts . ' '
1317+
if g:NERDTreeDirArrows
1318+
let treeParts = treeParts . ' '
1319+
else
1320+
if j ==# 1
1321+
let treeParts = treeParts . '| '
1322+
else
1323+
let treeParts = treeParts . ' '
1324+
endif
1325+
endif
13171326
endfor
13181327
endif
13191328

1329+
"get the last vertical tree part for this line which will be different
1330+
"if this node is the last child of its parent
1331+
if !g:NERDTreeDirArrows
1332+
if a:isLastChild
1333+
let treeParts = treeParts . '`'
1334+
else
1335+
let treeParts = treeParts . '|'
1336+
endif
1337+
endif
1338+
13201339
"smack the appropriate dir/file symbol on the line before the file/dir
13211340
"name itself
13221341
if self.path.isDirectory
13231342
if self.isOpen
1324-
let treeParts = treeParts . ''
1343+
if g:NERDTreeDirArrows
1344+
let treeParts = treeParts . ''
1345+
else
1346+
let treeParts = treeParts . '~'
1347+
endif
13251348
else
1326-
let treeParts = treeParts . ''
1349+
if g:NERDTreeDirArrows
1350+
let treeParts = treeParts . ''
1351+
else
1352+
let treeParts = treeParts . '+'
1353+
endif
13271354
endif
13281355
else
1329-
let treeParts = treeParts . ' '
1356+
if g:NERDTreeDirArrows
1357+
let treeParts = treeParts . ' '
1358+
else
1359+
let treeParts = treeParts . '-'
1360+
endif
13301361
endif
13311362
let line = treeParts . self.displayString()
13321363

@@ -3054,10 +3085,12 @@ function! s:getPath(ln)
30543085
return b:NERDTreeRoot.path
30553086
endif
30563087

3057-
" in case called from outside the tree
3058-
" if line !~# '^ *[|`▸▾ ]' || line =~# '^$'
3059-
" return {}
3060-
" endif
3088+
if !g:NERDTreeDirArrows
3089+
" in case called from outside the tree
3090+
if line !~# '^ *[|`▸▾ ]' || line =~# '^$'
3091+
return {}
3092+
endif
3093+
endif
30613094

30623095
if line ==# s:tree_up_dir_line
30633096
return b:NERDTreeRoot.path.getParent()

0 commit comments

Comments
 (0)