diff --git a/autoload/ag.vim b/autoload/ag.vim index 6703396b..f20aca1a 100644 --- a/autoload/ag.vim +++ b/autoload/ag.vim @@ -43,14 +43,48 @@ if !exists("g:ag_lhandler") let g:ag_lhandler="botright lopen" endif +if !exists("g:ag_qmapping_func") + let g:ag_qmapping_func="call ag#AgSetDefaultMappings('c')" " we're using the quickfix window +endif + +if !exists("g:ag_lmapping_func") + let g:ag_lmapping_func="call ag#AgSetDefaultMappings('l')" " we're using the location list +endif + if !exists("g:ag_mapping_message") let g:ag_mapping_message=1 endif +if !exists("g:ag_mapping_message_text") + let g:ag_mapping_message_text="ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" +endif + if !exists("g:ag_working_path_mode") let g:ag_working_path_mode = 'c' endif +function! ag#AgSetDefaultMappings(matches_window_prefix) + nnoremap h K + nnoremap H Kb + nnoremap o + nnoremap t T + nnoremap T TgT + nnoremap v HbJt + + exe 'nnoremap e :' . a:matches_window_prefix .'close' + exe 'nnoremap go :' . a:matches_window_prefix . 'open' + exe 'nnoremap q :' . a:matches_window_prefix . 'close' + + exe 'nnoremap gv :let b:height=winheight(0)H:' . a:matches_window_prefix . 'openJ:exe printf(":normal %d\c-w>_", b:height)' + " Interpretation: + " :let b:height=winheight(0) Get the height of the quickfix/location list window + " Open the current item in a new split + " H Slam the newly opened window against the left edge + " :copen -or- :lopen Open either the quickfix window or the location list (whichever we were using) + " J Slam the quickfix/location list window against the bottom edge + " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match +endfunction + function! ag#AgBuffer(cmd, args) let l:bufs = filter(range(1, bufnr('$')), 'buflisted(v:val)') let l:files = [] @@ -128,11 +162,11 @@ function! ag#Ag(cmd, args) if a:cmd =~# '^l' && l:match_count exe g:ag_lhandler let l:apply_mappings = g:ag_apply_lmappings - let l:matches_window_prefix = 'l' " we're using the location list + let l:ag_mapping_func = g:ag_lmapping_func elseif l:match_count exe g:ag_qhandler let l:apply_mappings = g:ag_apply_qmappings - let l:matches_window_prefix = 'c' " we're using the quickfix window + let l:ag_mapping_func = g:ag_qmapping_func endif " If highlighting is on, highlight the search keyword. @@ -145,28 +179,10 @@ function! ag#Ag(cmd, args) if l:match_count if l:apply_mappings - nnoremap h K - nnoremap H Kb - nnoremap o - nnoremap t T - nnoremap T TgT - nnoremap v HbJt - - exe 'nnoremap e :' . l:matches_window_prefix .'close' - exe 'nnoremap go :' . l:matches_window_prefix . 'open' - exe 'nnoremap q :' . l:matches_window_prefix . 'close' - - exe 'nnoremap gv :let b:height=winheight(0)H:' . l:matches_window_prefix . 'openJ:exe printf(":normal %d\c-w>_", b:height)' - " Interpretation: - " :let b:height=winheight(0) Get the height of the quickfix/location list window - " Open the current item in a new split - " H Slam the newly opened window against the left edge - " :copen -or- :lopen Open either the quickfix window or the location list (whichever we were using) - " J Slam the quickfix/location list window against the bottom edge - " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match - - if g:ag_mapping_message && l:apply_mappings - echom "ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" + exe l:ag_mapping_func + + if g:ag_mapping_message + echom g:ag_mapping_message_text endif endif else diff --git a/doc/ag.txt b/doc/ag.txt index e702c291..fdea9fcd 100644 --- a/doc/ag.txt +++ b/doc/ag.txt @@ -138,16 +138,36 @@ window is opened, or what size it is. Example: > let g:ag_qhandler="copen 20" < + *g:ag_lmapping_func* +A custom command used to set key mappings for the location list. Default: +"call ag#AgSetDefaultMappings('l')". Example: > + let g:ag_qhandler="call AgSetMyCustomMappings()" +< + + + *g:ag_qmapping_func* +A custom command used to set key mappings for the quickfix window. Default: +"call ag#AgSetDefaultMappings('c')". Example: > + let g:ag_qhandler="call AgSetMyCustomMappings()" +< *g:ag_mapping_message* Whether or not to show the message explaining the extra mappings that are added to the results list this plugin populates. This message is not shown if the mappings are not applied (see |g:ag_apply_qmappings| and -|g:ag_apply_lmappings| for more info. Default 1. Example: > +|g:ag_apply_lmappings| for more info). Default 1. Example: > let g:ag_mapping_message=0 < + *g:ag_mapping_message_text* +A custom message string to display when the results list window opens +(see |g:ag_mapping_message| and for more info). Default "ag.vim keys: q=quit +/e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same". +Example: > + let g:ag_mapping_message="Press q to close results list" +< + ============================================================================== -MAPPINGS *ag-mappings* +DEFAULT MAPPINGS *ag-mappings* The following keyboard shortcuts are available in the quickfix window: