diff --git a/README.md b/README.md index 4f65c4f..b7e823a 100644 --- a/README.md +++ b/README.md @@ -68,17 +68,26 @@ cabbrev SS SideSearch > How to search for multi-word terms? -Surround terms with double quotes +Use backslash `\` to escape spaces. Double quoted strings are no longer supported. ``` -:SideSearch "cats and dogs" +:SideSearch cats\ and\ dogs ``` -> How to pass extra args to `rg`? +> How to pass extra arguments to `rg`? -Just do it :) +Just do itâ„¢, but please add search terms first and extra arguments afterwards. ``` -:SideSearch -t js MyAwesomeComponent +:SideSearch MyAwesomeComponent -t js +``` + +> How to restrict the search path? + +Pass the search path as the last argument. If it is a valid relative or absolute path it is passed to the underlying +search program. Otherwise, SideSearch will guess the project's root directory. + +``` +:SideSearch MyAwesomeComponent -t js relative/path ``` > What happened to using The Silver Searcher? diff --git a/plugin/side-search.vim b/plugin/side-search.vim index d68e2d9..d070998 100644 --- a/plugin/side-search.vim +++ b/plugin/side-search.vim @@ -91,7 +91,7 @@ function! s:custom_mappings() abort nnoremap :call preview_main() nnoremap <2-LeftMouse> :call preview_main() nnoremap :call open_main() - nnoremap qf :silent exec 'grep!' b:escaped_query + nnoremap qf :silent exec 'grep!' b:escaped endfunction " Appends header guide to buffer @@ -187,7 +187,7 @@ endfunction " This will name the buffer the search term so it's easier to identify. " After opening the search results, the cursor should remain in it's " original position. -function! SideSearch(args) abort +function! SideSearch(term, ...) abort call s:defaults() let found = SideSearchWinnr() @@ -202,23 +202,25 @@ function! SideSearch(args) abort call s:append_guide() - " determine root directory - let l:cwd = s:guessProjectRoot() - " execute showing summary of stuff read (without silent) - let b:cmd = g:side_search_prg . ' ' . a:args . ' ' . l:cwd - " Thanks: https://github.com/rking/ag.vim/blob/master/autoload/ag.vim#L154 - let query = matchstr(a:args, "\\v(-)\@ ' . a:term " echom 'b:cmd => '.b:cmd silent execute 'read!' b:cmd " name the buffer something useful - silent execute 'file [SS '.a:args.', '.s:parse_matches().']' + silent execute 'file [SS ' . b:escaped . ', ' . s:parse_matches() . ']' " save search term in search register - " strip wrapped quotes as needed - let @/ = substitute(query, '\v([.\-])', "\\\\\\1", 'g') + let @/ = a:term " 1. go to top of file " 2. forward search the term @@ -233,4 +235,4 @@ function! SideSearch(args) abort endfunction " Create a command to call SideSearch -command! -complete=file -nargs=+ SideSearch call SideSearch() +command! -complete=file -nargs=+ SideSearch call SideSearch()