From 339cdae1af2b4c14a7d1e488e355b37317e90233 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 22 Nov 2014 18:15:29 +0100 Subject: [PATCH] Expose "open buffers" functionality for mapping References #123. --- autoload/startify.vim | 94 +++++++++++++++++++++---------------------- doc/startify.txt | 4 ++ plugin/startify.vim | 2 + 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index 5cff3cc..24f9224 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -143,7 +143,7 @@ function! startify#insane_in_the_membrane() abort nnoremap s :call set_mark('S') nnoremap t :call set_mark('T') nnoremap v :call set_mark('V') - nnoremap :call open_buffers(expand('')) + nnoremap :call startify#open_buffers() nnoremap <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+') nnoremap q :call close() @@ -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('') + 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('%') diff --git a/doc/startify.txt b/doc/startify.txt index 7876759..df4412c 100644 --- a/doc/startify.txt +++ b/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 , put this in your vimrc: +> + nmap o (startify-open-buffers) +< ============================================================================== COLORS *startify-colors* diff --git a/plugin/startify.vim b/plugin/startify.vim index 69b1279..502140e 100644 --- a/plugin/startify.vim +++ b/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() command! -nargs=? -bar -complete=customlist,startify#session_list SDelete call startify#session_delete() command! -nargs=0 -bar Startify call startify#insane_in_the_membrane() + +nnoremap (startify-open-buffers) :call startify#open_buffers()