Просмотр исходного кода

Expose "open buffers" functionality for mapping

References #123.
Marco Hinz 11 лет назад
Родитель
Сommit
339cdae1af
3 измененных файлов с 53 добавлено и 47 удалено
  1. 47 47
      autoload/startify.vim
  2. 4 0
      doc/startify.txt
  3. 2 0
      plugin/startify.vim

+ 47 - 47
autoload/startify.vim

@@ -143,7 +143,7 @@ function! startify#insane_in_the_membrane() abort
   nnoremap <buffer><silent> s             :call <sid>set_mark('S')<cr>
   nnoremap <buffer><silent> t             :call <sid>set_mark('T')<cr>
   nnoremap <buffer><silent> v             :call <sid>set_mark('V')<cr>
-  nnoremap <buffer><silent> <cr>          :call <sid>open_buffers(expand('<cword>'))<cr>
+  nnoremap <buffer><silent> <cr>          :call startify#open_buffers()<cr>
   nnoremap <buffer><silent> <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+')<cr>
   nnoremap <buffer><silent> q             :call <sid>close()<cr>
 
@@ -323,6 +323,52 @@ function! startify#session_list_as_string(lead, ...) abort
   return join(map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")'), "\n")
 endfunction
 
+" Function: #open_buffers {{{1
+function! startify#open_buffers() abort
+  " markers found; open one or more buffers
+  if exists('s:marked') && !empty(s:marked)
+    enew
+    setlocal nobuflisted
+
+    for val in values(s:marked)
+      let [path, type] = val[1:2]
+      let path = fnameescape(path)
+
+      if line2byte('$') == -1
+        " open in current window
+        execute 'edit' path
+      elseif type == 'S'
+        " open in split
+        execute 'split' path
+      elseif type == 'V'
+        " open in vsplit
+        execute 'vsplit' path
+      elseif type == 'T'
+        " open in tab
+        execute 'tabnew' path
+      else
+        " open in current window
+        execute 'edit' path
+      endif
+
+      call s:check_user_options()
+    endfor
+
+    " remove markers for next instance of :Startify
+    if exists('s:marked')
+      unlet s:marked
+    endif
+  " no markers found; open a single buffer
+  else
+    try
+      execute 'normal' expand('<cword>')
+    catch /E832/  " don't ask for undo encryption key twice
+      edit
+    catch /E325/  " swap file found
+    endtry
+  endif
+endfunction
+
 " Function: s:show_dir {{{1
 function! s:show_dir(cnt) abort
   if empty(v:oldfiles)
@@ -543,52 +589,6 @@ function! s:set_mark(type) abort
   setlocal nomodifiable nomodified
 endfunction
 
-" Function: s:open_buffers {{{1
-function! s:open_buffers(cword) abort
-  " markers found; open one or more buffers
-  if exists('s:marked') && !empty(s:marked)
-    enew
-    setlocal nobuflisted
-
-    for val in values(s:marked)
-      let [path, type] = val[1:2]
-      let path = fnameescape(path)
-
-      if line2byte('$') == -1
-        " open in current window
-        execute 'edit' path
-      elseif type == 'S'
-        " open in split
-        execute 'split' path
-      elseif type == 'V'
-        " open in vsplit
-        execute 'vsplit' path
-      elseif type == 'T'
-        " open in tab
-        execute 'tabnew' path
-      else
-        " open in current window
-        execute 'edit' path
-      endif
-
-      call s:check_user_options()
-    endfor
-
-    " remove markers for next instance of :Startify
-    if exists('s:marked')
-      unlet s:marked
-    endif
-  " no markers found; open a single buffer
-  else
-    try
-      execute 'normal' a:cword
-    catch /E832/  " don't ask for undo encryption key twice
-      edit
-    catch /E325/  " swap file found
-    endtry
-  endif
-endfunction
-
 " Function: s:check_user_options {{{1
 function! s:check_user_options() abort
   let path    = expand('%')

+ 4 - 0
doc/startify.txt

@@ -469,6 +469,10 @@ in a vertical split window or in a new tab.
 Open all marked entries. If nothing was marked beforehand, just open the
 current entry.
 
+If you want to use another key instead of <cr>, put this in your vimrc:
+>
+    nmap o <plug>(startify-open-buffers)
+<
 ==============================================================================
 COLORS                                                         *startify-colors*
 

+ 2 - 0
plugin/startify.vim

@@ -31,3 +31,5 @@ command! -nargs=? -bar -complete=customlist,startify#session_list SSave   call s
 command! -nargs=? -bar -complete=customlist,startify#session_list SLoad   call startify#session_load(<f-args>)
 command! -nargs=? -bar -complete=customlist,startify#session_list SDelete call startify#session_delete(<f-args>)
 command! -nargs=0 -bar Startify call startify#insane_in_the_membrane()
+
+nnoremap <silent><plug>(startify-open-buffers) :<c-u>call startify#open_buffers()<cr>