Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Shorcut improvements
Browse files Browse the repository at this point in the history
resolves rking#17, resolves rking#18
  • Loading branch information
albfan committed Dec 17, 2015
1 parent b9c857f commit f6e2164
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
52 changes: 45 additions & 7 deletions autoload/ag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ if !exists("g:ag_lhandler")
let g:ag_lhandler="botright lopen"
endif

if !exists("g:ag_nhandler")
let g:ag_nhandler="botright new"
endif

if !exists("g:ag_mapping_message")
let g:ag_mapping_message=1
endif
Expand Down Expand Up @@ -127,7 +131,8 @@ function! ag#AgGroup(ncontext, visualmode, fileregexp, args)

silent! wincmd P
if !&previewwindow
execute 'bo ' . &previewheight . ' new'
exe g:ag_nhandler
execute 'resize ' . &previewheight
set previewwindow
endif

Expand Down Expand Up @@ -186,13 +191,41 @@ function! ag#AgGroup(ncontext, visualmode, fileregexp, args)
setlocal foldcolumn=2
1
setlocal nomodifiable
map <buffer> o za
map <buffer> <space> zMzjzo
map <buffer> o zaj
map <buffer> <space> :call NextFold()<CR>
map <buffer> O :call ToggleEntireFold()<CR>
map <buffer> <Enter> :call OpenFile()<CR>
map <buffer> <Enter> :call OpenFile(0)<CR>
map <buffer> s :call OpenFile(1)<CR>
map <buffer> S :call OpenFile(2)<CR>
endfunction

" Find next fold or go back to first one
"
function NextFold()
let save_a_mark = getpos("'a")
let mark_a_exists = save_a_mark[1] == 0
mark a
execute 'normal zMzjzo'
if getpos('.')[1] == getpos("'a")[1]
"no movement go to first position
normal gg
execute 'normal zMzjzo'
endif
if mark_a_exists
call setpos("'a", save_a_mark)
else
delmark a
endif
endfunction

function! OpenFile()
" Open file for AgGroup selection
"
" forceSplit:
" 0 no
" 1 horizontal
" 2 vertical
"
function! OpenFile(forceSplit)
let curpos = line('.')
let line = getline(curpos)
if empty(line)
Expand Down Expand Up @@ -234,8 +267,13 @@ function! OpenFile()
let filename = getline(curpos)
let avaliable_windows = map(filter(range(0, bufnr('$')), 'bufwinnr(v:val)>=0 && buflisted(v:val)'), 'bufwinnr(v:val)')
let open_command = "edit"
if (empty(avaliable_windows))
let open_command = "split"
if a:forceSplit || empty(avaliable_windows)
if a:forceSplit > 1
wincmd k
let open_command = "vertical leftabove vsplit"
else
let open_command = "split"
endif
else
let winnr = get(avaliable_windows, 0)
exe winnr . "wincmd w"
Expand Down
8 changes: 8 additions & 0 deletions doc/ag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ the results in a split window.
o fold/unfold current file match
O fold/unfold all matches
<Enter> Goto selected file:line:col
<space> Open next fold search (cyclic)
s Goto selected file:line:col splitting horizontal above
S Goto selected file:line:col splitting vertical above

:AgBuffer[!] [options] {pattern} *:AgBuffer*

Expand Down Expand Up @@ -151,6 +154,11 @@ 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_nhandler*
A custom command used to open the AgGroup list after it's populated. Default:
"botright new". You might want to set this to change where it is opened.
Example: >
let g:ag_nhandler="topleft new"
<

*g:ag_mapping_message*
Expand Down
6 changes: 5 additions & 1 deletion plugin/ag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ command! -bang -nargs=* -complete=file AgFile call ag#Ag('grep<bang> -g', <q-arg
command! -bang -nargs=* -complete=help AgHelp call ag#AgHelp('grep<bang>',<q-args>)
command! -bang -nargs=* -complete=help LAgHelp call ag#AgHelp('lgrep<bang>',<q-args>)

if exists("g:ag_disable_shortcuts")
if !exists("g:ag_shortcuts")
let g:ag_shortcuts=1
endif

if exists("g:ag_shortcuts")
vnoremap <Leader>ag :call ag#AgGroup(v:count, 1, '', '')<CR>
nnoremap <Leader>ag :call ag#AgGroup(v:count, 0, '', '')<CR>
nnoremap <Leader>ra :call ag#AgGroupLast(v:count)<CR>
Expand Down

0 comments on commit f6e2164

Please sign in to comment.