aboutsummaryrefslogtreecommitdiff
path: root/autoload/select_old_files.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/select_old_files.vim')
-rw-r--r--autoload/select_old_files.vim33
1 files changed, 33 insertions, 0 deletions
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