如何在NERDTree中区分git忽略的文件和目录
答
从nerdtree-git-plugin修改,这个片段将自动忽略的亮点采用Commment
新版本NERDTree没有|-
类似前缀的文件(这会导致同步匹配失败?)。
function! GitDimIgnoredFiles()
let gitcmd = 'git -c color.status=false status -s --ignored'
if exists('b:NERDTree')
let root = b:NERDTree.root.path.str()
else
let root = './'
endif
let files = split(system(gitcmd.' '.root), '\n')
call GitFindIgnoredFiles(files)
endfunction
function! GitFindIgnoredFiles(files)
for file in a:files
let pre = file[0:1]
if pre == '!!'
let ignored = split(file[3:], '/')[-1]
exec 'syn match Comment #\<'.escape(ignored, '~').'\(\.\)\@!\># containedin=NERDTreeFile'
endif
endfor
endfunction
autocmd FileType nerdtree :call GitDimIgnoredFiles()
我粘贴这对的.vimrc,当出并在vim,并得到了很多错误,startind用'检测到错误而处理功能GitDimIgnoredFiles [9] .. GitFindIgnoredFiles: '然后接着大多'E402 :模式后的垃圾:/ path/to/a/folder // containedin = NERDTreeFile'和'E475:无效参数:Comment/path/to/a/folder // containedin = NERDTreeFile'。请指教。 – mljrg
已更新,以解决该错误,但仍是一种简化的方法。 – leaf
这可以成为一个完整高效的解决方案的开始。例如,它不会调暗排除的目录及其内容。 – mljrg