From 07b122f7b48141c8c35f675db1b596d9e28c8863 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Tue, 6 Dec 2016 20:56:54 +0100 Subject: [PATCH] Enforce mapping order when using Opposed to normal mappings, the definition order is important when using mappings. Simple test case: :enew | nnoremap 1 :echo "foo"| nnoremap 11 :echo "bar" Then hit 1 in normal mode. :enew | nnoremap 11 :echo "foo"| nnoremap 1 :echo "bar" Then hit 1 in normal mode again. References #252. --- autoload/startify.vim | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index c609f25..d6f49a8 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -728,9 +728,13 @@ function! s:set_mappings() abort nnoremap n ' j'[v:searchforward].'n' nnoremap N 'j '[v:searchforward].'N' - for k in keys(b:startify.entries) - execute 'nnoremap '. b:startify.entries[k].nowait b:startify.entries[k].index - \ ':call startify#open_buffers('. string(k) .')' + function! s:compare_by_index(foo, bar) + return a:foo.index - a:bar.index + endfunction + + for entry in sort(values(b:startify.entries), 's:compare_by_index') + execute 'nnoremap '. entry.nowait entry.index + \ ':call startify#open_buffers('. string(entry.line) .')' endfor " Prevent 'nnoremap j gj' mappings, since they would break navigation. @@ -851,6 +855,7 @@ function! s:register(line, index, type, cmd, path, wait) let b:startify.entries[a:line] = { \ 'index': a:index, \ 'type': a:type, + \ 'line': a:line, \ 'cmd': a:cmd, \ 'path': a:path, \ 'nowait': a:wait,