From 05777de3c49a5effffbe130e0e290a25d77b841e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 21 Jun 2019 17:54:30 +1200 Subject: Committing plugin as I've got it --- autoload/select_old_files.vim | 33 +++++++++++++++++++++++++++++++++ plugin/select_old_files.vim | 20 ++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 autoload/select_old_files.vim create mode 100644 plugin/select_old_files.vim diff --git a/autoload/select_old_files.vim b/autoload/select_old_files.vim new file mode 100644 index 0000000..dcc6657 --- /dev/null +++ b/autoload/select_old_files.vim @@ -0,0 +1,33 @@ +" Entry point to command function with one optional argument, the count of +" v:oldfiles wanted for selection. +" +function! select_old_files#(...) abort + + " Check we didn't receive too many arguments + if a:0 > 1 + echoerr 'Too many arguments' + endif + + " If an argument was provided, use that as the limit; failing that, use + " a global variable g:select_old_files_limit if set; failing that, use two + " less than the current number of screen lines, filling the screen but not + " forcing a pager. + " + let limit = a:0 == 1 + \ ? a:1 : get(g:, 'select_old_files_limit', &lines - 2) + + " Check the count provided makes sense: a non-zero positive integer + if limit <= 0 + echoerr 'Invalid count' + endif + + " Save the current value of v:oldfiles and reassign it to have the number of + " items specified, and then :browse it. Once that's done, whether or not + " the user chose a file to edit, put the previous v:oldfiles value back. + " + let oldfiles = v:oldfiles + let v:oldfiles = v:oldfiles[:limit - 1] + browse oldfiles + let v:oldfiles = oldfiles + +endfunction diff --git a/plugin/select_old_files.vim b/plugin/select_old_files.vim new file mode 100644 index 0000000..c2a477e --- /dev/null +++ b/plugin/select_old_files.vim @@ -0,0 +1,20 @@ +" +" select_old_files.vim: Slightly enhanced `:browse oldfiles` that limits the +" count of selectable files, defaulting to just short of the window height, to +" avoid a pager. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('loaded_select_old_files') || &compatible || !exists(':oldfiles') + finish +endif +let loaded_select_old_files = 1 + +" User command accepts single optional integer limiting files listing +command! -bar -nargs=? SelectOldFiles + \ call select_old_files#() + +" Normal mode mapping calls command with no arguments +nnoremap (SelectOldFiles) + \ :SelectOldFiles -- cgit v1.2.3