diff options
Diffstat (limited to 'contrib/vim')
-rw-r--r-- | contrib/vim/README.md (renamed from contrib/vim/README) | 47 | ||||
-rw-r--r-- | contrib/vim/plugin/rf.vim | 16 |
2 files changed, 49 insertions, 14 deletions
diff --git a/contrib/vim/README b/contrib/vim/README.md index 5752ed0..f108c89 100644 --- a/contrib/vim/README +++ b/contrib/vim/README.md @@ -1,14 +1,31 @@ -This directory provides basic rf integration in Vim. +# rf-vim -It can be installed from this directory using make: +> Simple `rf` Vim integration - make install +### Installation -The plugin provides two functions: +__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 +``` -*rf* +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 +__RF:__ This function runs a getchar() loop, allowing you to search from the root of the current working directory, using only substring patterns, @@ -17,18 +34,22 @@ exposing more of the functionality that rf provides. I usually bind the function like so: - map <c-p> :RF <CR> +``` +map <c-p> :RF <CR> +``` 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, +to the implementation, just make sure that any `.rfignore` files, whether local or global are ignoring everything that can be ignored. -*rf grep* +__RFGrep:__ - :RFGrep search-pattern filename-pattern +``` +: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 @@ -36,10 +57,12 @@ 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* +### 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 +``` +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 |