简体   繁体   中英

vim-NERDTree: order bookmarks?

Is there a way to order the bookmarks I see with the NERDTree vim plugin?

I feel like this should be simple, but I don't know how to do this. I vim'ed ~/.NERDTreeBookmarks and saw that in that file, the bookmarks are in the right order, but it seems to continuously reorganize the bookmarks according to the order I use them -- which is not what I want. I also did :ReadBookmarks command and that didn't seem to change order.

I had the same problem, and managed to turn off NERDTree's wacky bookmark sorting. Open the NERD_tree.vim plugin file (usually ~/.vim/plugin/NERD_tree.vim ). Search for this line:

call s:Bookmark.Sort()

There should be two instances of the line (in NERDTree version 4.2.0 they're on lines 209 and 286). Comment out both lines by adding " in front of them like this:

"call s:Bookmark.Sort()

Now you can edit ~/.NERDTreeBookmarks and your bookmarks will show up in NERDTree in the same order as in the file. You can use :ReadBookmarks to refresh your bookmarks list after editing the file.

As an update to alxm's excellent answer above, the line(s) have been moved into a new file. On my hard drive it's in ~/.vim/bundle/nerdtree/lib/nerdtree/bookmark.vim (I use vundle). In a vanilla vim installation it would most likely be in ~/.vim/plugin/nerdtree/lib/nerdtree/bookmark.vim .

1. Edit your bookmark.vim file

I commented out the line that starts with call sort... (line 246), like this:

" This is in ~/.vim/<PLUGINDIR>/nerdtree/lib/nerdtree/bookmark.vim

" FUNCTION: Bookmark.Sort() {{{1
" Class method that sorts all bookmarks
function! s:Bookmark.Sort()
    let CompareFunc = function("nerdtree#compareBookmarks")
    "call sort(s:Bookmark.Bookmarks(), CompareFunc)
endfunction

2. Quit vim

Exit out of vim because you want to reload your plugins, specifically NERDTree.

3. Edit your ~/.NERDTreeBookmarks file.

Put them in the order you want them in. NERDTree now respects your wishes. Your solemn, heartfelt bookmark sorting wishes.

4. Fire up vim again

Of course everyone already knows this, but I thought this answer needed a fourth step.

Not sure since when though, you can now set NERDTreeBookmarksSort instead.

let g:NERDTreeBookmarksSort=0

Then edit ~/.NERDTreeBookmarks as you want to order.

Check :help NERDTreeBookmarksSort for more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM