Updates
This commit is contained in:
1
vim/bundle/Vundle.vim
Submodule
1
vim/bundle/Vundle.vim
Submodule
Submodule vim/bundle/Vundle.vim added at 0b28e334e6
@@ -18,7 +18,7 @@ git clone https://github.com/ggreer/the_silver_searcher ag && cd ag && ./build.s
|
||||
* Then, if you're using [pathogen](https://github.com/tpope/vim-pathogen):
|
||||
|
||||
```sh
|
||||
cd ~/.vim/bundle && git clone https://github.com/rking/ag.vim ag && vim +HelpTags
|
||||
cd ~/.vim/bundle && git clone https://github.com/rking/ag.vim ag && vim +Helptags
|
||||
```
|
||||
|
||||
* Or, if you're using [Vundle](https://github.com/gmarik/vundle):
|
||||
@@ -27,7 +27,7 @@ cd ~/.vim/bundle && git clone https://github.com/rking/ag.vim ag && vim +HelpTag
|
||||
echo "Bundle 'rking/ag.vim'" >> ~/.vimrc && vim +BundleInstall
|
||||
```
|
||||
|
||||
### Configuation
|
||||
### Configuration
|
||||
|
||||
You can specify a custom ag name and path in your .vimrc like so:
|
||||
|
||||
@@ -49,12 +49,13 @@ Just like where you use :grep, :grepadd, :lgrep, and :lgrepadd, you can use `:Ag
|
||||
|
||||
Some characters have special meaning, and need to be escaped your search pattern. For instance, '#'. You have to escape it like this `:Ag '\\\#define foo'` to search for `#define foo`. (From [blueyed in issue #5](https://github.com/mileszs/ack.vim/issues/5).)
|
||||
|
||||
Sometimes `git grep` is even faster, though in my experience it's not noticably so.
|
||||
Sometimes `git grep` is even faster, though in my experience it's not noticeably so.
|
||||
|
||||
### Keyboard Shortcuts ###
|
||||
|
||||
In the quickfix window, you can use:
|
||||
|
||||
e to open file and close the quickfix window
|
||||
o to open (same as enter)
|
||||
go to preview file (open but maintain focus on ag.vim results)
|
||||
t to open in new tab
|
||||
|
||||
@@ -6,11 +6,11 @@ if !exists("g:agprg")
|
||||
endif
|
||||
|
||||
if !exists("g:ag_apply_qmappings")
|
||||
let g:ag_apply_qmappings = !exists("g:ag_qhandler")
|
||||
let g:ag_apply_qmappings=1
|
||||
endif
|
||||
|
||||
if !exists("g:ag_apply_lmappings")
|
||||
let g:ag_apply_lmappings = !exists("g:ag_lhandler")
|
||||
let g:ag_apply_lmappings=1
|
||||
endif
|
||||
|
||||
if !exists("g:ag_qhandler")
|
||||
@@ -21,7 +21,19 @@ if !exists("g:ag_lhandler")
|
||||
let g:ag_lhandler="botright lopen"
|
||||
endif
|
||||
|
||||
if !exists("g:ag_mapping_message")
|
||||
let g:ag_mapping_message=1
|
||||
endif
|
||||
|
||||
function! ag#Ag(cmd, args)
|
||||
let l:ag_executable = get(split(g:agprg, " "), 0)
|
||||
|
||||
" Ensure that `ag` is installed
|
||||
if !executable(l:ag_executable)
|
||||
echoe "Ag command '" . l:ag_executable . "' was not found. Is the silver searcher installed and on your $PATH?"
|
||||
return
|
||||
endif
|
||||
|
||||
" If no pattern is provided, search for the word under the cursor
|
||||
if empty(a:args)
|
||||
let l:grepargs = expand("<cword>")
|
||||
@@ -31,28 +43,45 @@ function! ag#Ag(cmd, args)
|
||||
|
||||
" Format, used to manage column jump
|
||||
if a:cmd =~# '-g$'
|
||||
let s:agformat_backup=g:agformat
|
||||
let g:agformat="%f"
|
||||
else
|
||||
elseif exists("s:agformat_backup")
|
||||
let g:agformat=s:agformat_backup
|
||||
elseif !exists("g:agformat")
|
||||
let g:agformat="%f:%l:%c:%m"
|
||||
end
|
||||
endif
|
||||
|
||||
let grepprg_bak=&grepprg
|
||||
let grepformat_bak=&grepformat
|
||||
let l:grepprg_bak=&grepprg
|
||||
let l:grepformat_bak=&grepformat
|
||||
let l:t_ti_bak=&t_ti
|
||||
let l:t_te_bak=&t_te
|
||||
try
|
||||
let &grepprg=g:agprg
|
||||
let &grepformat=g:agformat
|
||||
set t_ti=
|
||||
set t_te=
|
||||
silent execute a:cmd . " " . escape(l:grepargs, '|')
|
||||
finally
|
||||
let &grepprg=grepprg_bak
|
||||
let &grepformat=grepformat_bak
|
||||
let &grepprg=l:grepprg_bak
|
||||
let &grepformat=l:grepformat_bak
|
||||
let &t_ti=l:t_ti_bak
|
||||
let &t_te=l:t_te_bak
|
||||
endtry
|
||||
|
||||
if a:cmd =~# '^l'
|
||||
let l:match_count = len(getloclist(winnr()))
|
||||
else
|
||||
let l:match_count = len(getqflist())
|
||||
endif
|
||||
|
||||
if a:cmd =~# '^l' && l:match_count
|
||||
exe g:ag_lhandler
|
||||
let l:apply_mappings = g:ag_apply_lmappings
|
||||
else
|
||||
let l:matches_window_prefix = 'l' " we're using the location list
|
||||
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
|
||||
endif
|
||||
|
||||
" If highlighting is on, highlight the search keyword.
|
||||
@@ -63,17 +92,34 @@ function! ag#Ag(cmd, args)
|
||||
|
||||
redraw!
|
||||
|
||||
if l:apply_mappings
|
||||
exec "nnoremap <silent> <buffer> q :ccl<CR>"
|
||||
exec "nnoremap <silent> <buffer> t <C-W><CR><C-W>T"
|
||||
exec "nnoremap <silent> <buffer> T <C-W><CR><C-W>TgT<C-W><C-W>"
|
||||
exec "nnoremap <silent> <buffer> o <CR>"
|
||||
exec "nnoremap <silent> <buffer> go <CR><C-W><C-W>"
|
||||
exec "nnoremap <silent> <buffer> h <C-W><CR><C-W>K"
|
||||
exec "nnoremap <silent> <buffer> H <C-W><CR><C-W>K<C-W>b"
|
||||
exec "nnoremap <silent> <buffer> v <C-W><CR><C-W>H<C-W>b<C-W>J<C-W>t"
|
||||
exec "nnoremap <silent> <buffer> gv <C-W><CR><C-W>H<C-W>b<C-W>J"
|
||||
echom "ag.vim keys: q=quit <cr>/t/h/v=enter/tab/split/vsplit go/T/H/gv=preview versions of same"
|
||||
if l:match_count
|
||||
if l:apply_mappings
|
||||
nnoremap <silent> <buffer> h <C-W><CR><C-w>K
|
||||
nnoremap <silent> <buffer> H <C-W><CR><C-w>K<C-w>b
|
||||
nnoremap <silent> <buffer> o <CR>
|
||||
nnoremap <silent> <buffer> t <C-w><CR><C-w>T
|
||||
nnoremap <silent> <buffer> T <C-w><CR><C-w>TgT<C-W><C-W>
|
||||
nnoremap <silent> <buffer> v <C-w><CR><C-w>H<C-W>b<C-W>J<C-W>t
|
||||
|
||||
exe 'nnoremap <silent> <buffer> e <CR><C-w><C-w>:' . l:matches_window_prefix .'close<CR>'
|
||||
exe 'nnoremap <silent> <buffer> go <CR>:' . l:matches_window_prefix . 'open<CR>'
|
||||
exe 'nnoremap <silent> <buffer> q :' . l:matches_window_prefix . 'close<CR>'
|
||||
|
||||
exe 'nnoremap <silent> <buffer> gv :let b:height=winheight(0)<CR><C-w><CR><C-w>H:' . l:matches_window_prefix . 'open<CR><C-w>J:exe printf(":normal %d\<lt>c-w>_", b:height)<CR>'
|
||||
" Interpretation:
|
||||
" :let b:height=winheight(0)<CR> Get the height of the quickfix/location list window
|
||||
" <CR><C-w> Open the current item in a new split
|
||||
" <C-w>H Slam the newly opened window against the left edge
|
||||
" :copen<CR> -or- :lopen<CR> Open either the quickfix window or the location list (whichever we were using)
|
||||
" <C-w>J Slam the quickfix/location list window against the bottom edge
|
||||
" :exe printf(":normal %d\<lt>c-w>_", b:height)<CR> 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 <cr>/e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same"
|
||||
endif
|
||||
endif
|
||||
else
|
||||
echom 'No matches for "'.a:args.'"'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -85,17 +131,17 @@ function! ag#AgFromSearch(cmd, args)
|
||||
endfunction
|
||||
|
||||
function! ag#GetDocLocations()
|
||||
let dp = ''
|
||||
for p in split(&rtp,',')
|
||||
let p = p.'/doc/'
|
||||
if isdirectory(p)
|
||||
let dp = p.'*.txt '.dp
|
||||
endif
|
||||
endfor
|
||||
return dp
|
||||
let dp = ''
|
||||
for p in split(&runtimepath,',')
|
||||
let p = p.'/doc/'
|
||||
if isdirectory(p)
|
||||
let dp = p.'*.txt '.dp
|
||||
endif
|
||||
endfor
|
||||
return dp
|
||||
endfunction
|
||||
|
||||
function! ag#AgHelp(cmd,args)
|
||||
let args = a:args.' '.ag#GetDocLocations()
|
||||
call ag#Ag(a:cmd,args)
|
||||
let args = a:args.' '.ag#GetDocLocations()
|
||||
call ag#Ag(a:cmd,args)
|
||||
endfunction
|
||||
|
||||
@@ -54,13 +54,73 @@ with the line number of the occurrence, once for each occurrence. <Enter> on
|
||||
a line in this window will open the file, and place the cursor on the matching
|
||||
line.
|
||||
|
||||
See http://betterthangrep.com/ for more information.
|
||||
See http://geoff.greer.fm/2011/12/27/the-silver-searcher-better-than-ack/ for
|
||||
more information.
|
||||
|
||||
==============================================================================
|
||||
OPTIONS *ag-options*
|
||||
|
||||
*g:agprg*
|
||||
The location of the Ag program, and any options you want passed to it before
|
||||
searching. Default: "ag --column". Example: >
|
||||
let g:agprg="ag --column --smart-case"
|
||||
<
|
||||
|
||||
*g:aghighlight*
|
||||
If 1, highlight the search terms after searching. Default: 0. Example: >
|
||||
let g:aghighlight=1
|
||||
<
|
||||
|
||||
*g:agformat*
|
||||
Format to recognize the matches. See 'errorformat' for more info. Default:
|
||||
"%f" when searching for files, "%f:%l:%c:%m" if not otherwise set. For
|
||||
example, if your `g:agprg` is set to just "ag" (no column numbers in the
|
||||
output, so when you jump to a match your cursor will be on the start of the
|
||||
line): >
|
||||
let g:agformat="%f:%l:%m"
|
||||
<
|
||||
|
||||
*g:ag_apply_lmappings*
|
||||
Whether or not to add custom mappings to location list windows opened by this
|
||||
plugin. Only applies if you're using the location list. Default 1. Example: >
|
||||
let g:ag_apply_lmappings=0
|
||||
<
|
||||
|
||||
*g:ag_apply_qmappings*
|
||||
Whether or not to add custom mappings to quickfix windows opened by this
|
||||
plugin. Only applies if you're using the error list. Default 1. Example: >
|
||||
let g:ag_apply_qmappings=0
|
||||
<
|
||||
|
||||
*g:ag_lhandler*
|
||||
A custom command used to open the location list after it's populated.
|
||||
Default: "botright lopen". You might want to set this to change where the
|
||||
location list is opened, or what size it is. Example: >
|
||||
let g:ag_lhandler="topleft lopen"
|
||||
<
|
||||
|
||||
*g:ag_qhandler*
|
||||
A custom command used to open the error list after it's populated. Default:
|
||||
"botright copen". You might want to set this to change where the quickfix
|
||||
window is opened, or what size it is. Example: >
|
||||
let g:ag_qhandler="copen 20"
|
||||
<
|
||||
|
||||
*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: >
|
||||
let g:ag_mapping_message=0
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
MAPPINGS *ag-mappings*
|
||||
|
||||
The following keyboard shortcuts are available in the quickfix window:
|
||||
|
||||
e open file and close the quickfix window.
|
||||
|
||||
o open file (same as enter).
|
||||
|
||||
go preview file (open but maintain focus on ag.vim results).
|
||||
@@ -78,3 +138,5 @@ v open in vertical split.
|
||||
gv open in vertical split silently.
|
||||
|
||||
q close the quickfix window.
|
||||
|
||||
vim:tw=78:fo=tcq2:ft=help:norl:
|
||||
|
||||
Reference in New Issue
Block a user