aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-21 17:54:30 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-21 23:42:27 +1200
commit05777de3c49a5effffbe130e0e290a25d77b841e (patch)
treeb17024db925f723c5f1c71f0c2128487cfeff731
downloadvim-select-old-files-05777de3c49a5effffbe130e0e290a25d77b841e.tar.gz
vim-select-old-files-05777de3c49a5effffbe130e0e290a25d77b841e.zip
Committing plugin as I've got it
-rw-r--r--autoload/select_old_files.vim33
-rw-r--r--plugin/select_old_files.vim20
2 files changed, 53 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
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 <tom@sanctum.geek.nz>
+" 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#(<f-args>)
+
+" Normal mode mapping calls command with no arguments
+nnoremap <Plug>(SelectOldFiles)
+ \ :<C-U>SelectOldFiles<CR>