diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt index 8f214cb..42c31cc 100644 --- a/doc/NERDTree.txt +++ b/doc/NERDTree.txt @@ -995,17 +995,33 @@ appended to the array. The regex '\/$' should be used to match directory nodes. +A special flag can be used to sort by the modification timestamps of files and +directories. It is either '[[timestamp]]' for ascending, or '[[-timestamp]]' +for descending. If placed at the beginning of the list, files and directories +are sorted by timestamp, and then by the remaining items in the sort order +list. If this flag is in any other position of the list, timestamp sorting is +done secondarily. See examples 4, 5, and 6 below. + After this sorting is done, the files in each group are sorted alphabetically. Other examples: > (1) ['*', '\/$'] (2) [] (3) ['\/$', '\.rb$', '\.php$', '*', '\.swp$', '\.bak$', '\~$'] + (4) ['[[timestamp]]'] + (5) ['\/$', '*', '[[-timestamp]]'] + (6) ['\.md$', '\.c$', '[[-timestamp]]', '*'] < 1. Directories will appear last, everything else will appear above. 2. Everything will simply appear in alphabetical order. 3. Dirs will appear first, then ruby and php. Swap files, bak files and vim backup files will appear last with everything else preceding them. +4. All files and directories are sorted by timestamp, oldest first. If any + files have identical timestamps, they are sorted alphabetically. +5. Directories are first, newest to oldest, then everything else, newest to + oldest. +6. Markdown files first, followed by C source files, then everything else. + Each group is shown newest to oldest. ------------------------------------------------------------------------------ *'NERDTreeStatusline'* diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 912c537..32c9cdb 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -392,7 +392,17 @@ endfunction " FUNCTION: Path.getSortKey() {{{1 " returns a key used in compare function for sorting function! s:Path.getSortKey() - if !exists("self._sortKey") || g:NERDTreeSortOrder !=# g:NERDTreeOldSortOrder + let l:ascending = index(g:NERDTreeSortOrder,'[[timestamp]]') + let l:descending = index(g:NERDTreeSortOrder,'[[-timestamp]]') + if !exists("self._sortKey") || g:NERDTreeSortOrder !=# g:NERDTreeOldSortOrder || l:ascending >= 0 || l:descending >= 0 + let self._sortKey = [self.getSortOrderIndex()] + + if l:descending >= 0 + call insert(self._sortKey, -getftime(self.str()), l:descending == 0 ? 0 : len(self._sortKey)) + elseif l:ascending >= 0 + call insert(self._sortKey, getftime(self.str()), l:ascending == 0 ? 0 : len(self._sortKey)) + endif + let path = self.getLastPathComponent(1) if !g:NERDTreeSortHiddenFirst let path = substitute(path, '^[._]', '', '') @@ -400,13 +410,9 @@ function! s:Path.getSortKey() if !g:NERDTreeCaseSensitiveSort let path = tolower(path) endif - if !g:NERDTreeNaturalSort - let self._sortKey = [self.getSortOrderIndex(), path] - else - let self._sortKey = [self.getSortOrderIndex()] + self._splitChunks(path) - endif - endif + call extend(self._sortKey, (g:NERDTreeNaturalSort ? self._splitChunks(path) : [path])) + endif return self._sortKey endfunction