From a40bd8adb20715582813fb8399dd37e4efee9b37 Mon Sep 17 00:00:00 2001 From: Rory Bradford Date: Sat, 10 Oct 2020 10:22:39 +0100 Subject: Improve Vim integration Signed-off-by: Rory Bradford --- contrib/vim/README | 45 ------------------------------- contrib/vim/README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++ contrib/vim/plugin/rf.vim | 16 +++++++++-- 3 files changed, 82 insertions(+), 47 deletions(-) delete mode 100644 contrib/vim/README create mode 100644 contrib/vim/README.md (limited to 'contrib/vim') diff --git a/contrib/vim/README b/contrib/vim/README deleted file mode 100644 index 5752ed0..0000000 --- a/contrib/vim/README +++ /dev/null @@ -1,45 +0,0 @@ -This directory provides basic rf integration in Vim. - -It can be installed from this directory using make: - - make install - -The plugin provides two functions: - -*rf* - - :RF - -This function runs a getchar() loop, allowing you to search from the -root of the current working directory, using only substring patterns, -the idea being that it is very quick and simple to use, rather than -exposing more of the functionality that rf provides. - -I usually bind the function like so: - - map :RF - -The function is very simple and will call rf with your pattern -*at every key stroke*. Usually this is performant enough, but -with extremely large directory trees, you may have to wait several -seconds for results, which isn't great. Aside from any improvements -to the implementation, just make sure that any .rfignore files, -whether local or global are ignoring everything that can be ignored. - -*rf grep* - - :RFGrep search-pattern filename-pattern - -This function is a wrapper around `grep -r` and rf. It allows you -to grep recursively over a smaller subset of files. Again the -implementation is very simple but with very large directory trees -or with filename patterns that match a lot of files you may -hit the argument limit for grep. - -*Issues* - -Aside from the above mentioned limitations and issues, if you -are using anything other than a "Bourne" shell (bash, ksh, zsh, sh) -the functions may not work, in that case you may want to explictly: - - set shell=sh diff --git a/contrib/vim/README.md b/contrib/vim/README.md new file mode 100644 index 0000000..f108c89 --- /dev/null +++ b/contrib/vim/README.md @@ -0,0 +1,68 @@ +# rf-vim + +> Simple `rf` Vim integration + +### Installation + +__Manual installation:__ + +If you are using default Vim paths (so not Neovim for example) you can +just run `make install`. Otherwise you should just be able to modify your +`runtimepath` and add `~/.vim/after/`. + +__Using vim-plug, Vundle, et al:__ + +```viml +Plug 'roryrjb/rf', { 'rtp': 'contrib/vim' } " vim-plug +Plugin 'roryrjb/rf', { 'rtp': 'contrib/vim' } " Vundle +``` + +Other plugin systems will likely have very similar options. In a nutshell +the vim plugin provided here isn't in the root of the repo and assumes +you have `rf` already installed and present in your `$PATH`. + +### Usage + +The plugin provides two functions: + +__RF:__ + +This function runs a getchar() loop, allowing you to search from the +root of the current working directory, using only substring patterns, +the idea being that it is very quick and simple to use, rather than +exposing more of the functionality that rf provides. + +I usually bind the function like so: + +``` +map :RF +``` + +The function is very simple and will call rf with your pattern +*at every key stroke*. Usually this is performant enough, but +with extremely large directory trees, you may have to wait several +seconds for results, which isn't great. Aside from any improvements +to the implementation, just make sure that any `.rfignore` files, +whether local or global are ignoring everything that can be ignored. + +__RFGrep:__ + +``` +:RFGrep search-pattern filename-pattern +``` + +This function is a wrapper around `grep -r` and rf. It allows you +to grep recursively over a smaller subset of files. Again the +implementation is very simple but with very large directory trees +or with filename patterns that match a lot of files you may +hit the argument limit for grep. + +### Issues + +Aside from the above mentioned limitations and issues, if you +are using anything other than a "Bourne" shell (bash, ksh, zsh, sh) +the functions may not work, in that case you may want to explictly: + +``` +set shell=sh +``` diff --git a/contrib/vim/plugin/rf.vim b/contrib/vim/plugin/rf.vim index cf4649b..4ea281c 100644 --- a/contrib/vim/plugin/rf.vim +++ b/contrib/vim/plugin/rf.vim @@ -3,6 +3,7 @@ if exists('loaded_rf') endif let loaded_rf = 1 +let g:rf_prefix = "" set errorformat+=%f @@ -60,15 +61,26 @@ function! g:RFPrompt() echo "RF: " . l:rf_pattern redraw - let results = system('rf -ws -- ' . shellescape(l:rf_pattern)) + if len(g:rf_prefix) + let results = system('rf -l9 -d ' . shellescape(g:rf_prefix) . ' -s -- ' . shellescape(l:rf_pattern)) + else + let results = system('rf -l9 -ws -- ' . shellescape(l:rf_pattern)) + endif + let results_list = split(results, '\n') let l:rf_results = results_list if len(results_list) > 0 - cgete results | copen 9 + if len(results_list) < 9 + execute "cgete results | copen " . len(results_list) + else + cgete results | copen 9 + endif + redraw else cexpr [] + cclose endif else let l:rf_cmd = 0 -- cgit 1.4.1-2-gfad0