From 72195cf648af3c9db85a0f864574965dc6b8409d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 16 Jun 2019 20:46:57 +1200 Subject: Refactor select_old_files.vim to allow count --- vim/autoload/select_old_files.vim | 16 +++++++++++++--- vim/plugin/select_old_files.vim | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/vim/autoload/select_old_files.vim b/vim/autoload/select_old_files.vim index 518b98d4..aceff110 100644 --- a/vim/autoload/select_old_files.vim +++ b/vim/autoload/select_old_files.vim @@ -1,7 +1,17 @@ -function! select_old_files#() abort +function! select_old_files#(...) abort + if a:0 + if a:1 =~# '^\d\+$' + let limit = a:1 + else + echoerr 'Invalid count' + endif + elseif exists('g:select_old_files_limit') + let limit = g:select_old_files_limit + else + let limit = &lines - 2 + endif let oldfiles = v:oldfiles - let limit = get(g:, 'select_old_files_limit', &lines - 1) - let v:oldfiles = v:oldfiles[:limit-2] + let v:oldfiles = v:oldfiles[:limit - 1] browse oldfiles let v:oldfiles = oldfiles endfunction diff --git a/vim/plugin/select_old_files.vim b/vim/plugin/select_old_files.vim index c03f0c39..77c7746e 100644 --- a/vim/plugin/select_old_files.vim +++ b/vim/plugin/select_old_files.vim @@ -2,7 +2,7 @@ if exists('loaded_select_old_files') || &compatible || !exists(':oldfiles') finish endif let loaded_select_old_files = 1 -command! -bar SelectOldFiles - \ call select_old_files#() +command! -bar -nargs=? SelectOldFiles + \ call select_old_files#() nnoremap SelectOldFiles \ :SelectOldFiles -- cgit v1.2.3