ag.vim icon indicating copy to clipboard operation
ag.vim copied to clipboard

Mappings

Open amerlyq opened this issue 11 years ago • 9 comments

Could you make mappings changeable in .vimrc? (Like in https://github.com/Valloric/ListToggle -- and itegrate its functionality -- only two mappings really! if possible).

In current state I can't replace mappings which need 'l:matches_window_prefix' to be set. As workaround, this file local var can be replaced with buffer local -- then I could use it in ftplugin for my own mappings.

P.S. At work I often search in kernel sources and preview feature 'go' is very useful for it. But pressing 'go' for 20-50 entries isn't much pleasing. As temporary workaround I use direct mapping in ftplugin/qf.vim "nnoremap <Space> <CR>:copen<CR>". But in such case I can't use location lists (I need that l:matches_window_prefix, which local to your plugin only :( )

amerlyq avatar Dec 15 '14 12:12 amerlyq

How about your proper mappings in qf.vim by adding (as a starter)

let s:qf_mappings = {
      \ "o": "<CR>",
      \ "O": "<CR><c-w>p",
      \ "q": "<C-W>c" }

for key_map in items(s:qf_mappings)
  execute printf("nnoremap <buffer><nowait><silent> %s %s", get(key_map, 0), get(key_map, 1))
endfor

?

This way, they are available even if the qflist was populated by other means than ag.vim.

NB: O is Ag's go

Konfekt avatar Jan 29 '15 15:01 Konfekt

However this snippet have not solved problem of l:matches_window_prefix, which determines kind of window we are working in, but you gave me one more viewpoint for idea. So, using your link notion at https://github.com/thinca/vim-qfreplace/issues/5 , resulting solution seems like:

" file: ~/.vim/after/ftplugin/qf.vim

" Thanks to: https://github.com/romainl/dotvim/blob/master/bundle/qf/after/ftplugin/qf.vim
" are we in a location list or a quickfix list?
let b:isLoc = len(getloclist(0)) > 0 ? 1 : 0
let b:wPref = b:isLoc ? 'l' : 'c'

"" Rule of Thumb: reuse editing mappings, and don't touch navigation
" q/<Space> - close / jump,
" o/O - preview/jump of and stay,        I - jump into and close,
" x/X - exchange to tab foregr/backgr,   S/H - split vert/horz,
let s:qf_mappings = {
      \ 'q' : ':#close<CR>',
      \ 'o' : '<CR><C-w>p',
      \ 'O' : '<CR>',
      \ 'I' : '<CR><C-w><C-w>:#close<CR>',
      \ 'S' : '<C-w><CR><C-w>L<C-w>p<C-w>J<C-w>p',
      \ 'H' : '<C-W><CR><C-w>K<C-w>b',
      \ 'x' : '<C-w><CR><C-w>T',
      \ 'X' : '<C-w><CR><C-w>TgT<C-W><C-W>',
      \ '<Space>' : '<CR>',
\ }

for key_map in items(s:qf_mappings)
  exec printf("nnoremap <buffer><nowait><silent> %s %s", get(key_map, 0)
                    \ , substitute(get(key_map, 1), '#', b:wPref, 'g'))
endfor

Issue can be closed, due to changed solution orientation.

amerlyq avatar Mar 10 '15 22:03 amerlyq

Cool,

Note that the solution further down in the qfreplace thread is more stable than that by getloclist().

Konfekt avatar Mar 11 '15 00:03 Konfekt

When albfan/ag.vim #21 enabling user customization will be implemented and merged into trunk, this issue could be finally closed.

amerlyq avatar Nov 21 '15 18:11 amerlyq

@amerlyq I'm using rking/ag.vm .how about you fork, does it contains replace func? just like easygrep

wsdjeg avatar Dec 14 '15 14:12 wsdjeg

Don't know what about vim-easygrep, because its code for me seemed rather obscure and overbloated to try it even once. I use combo of ag.vim with quickfix-reflector.vim when need to do some multi-file replacements. For me editing directly in qf seems much easier.

amerlyq avatar Dec 14 '15 14:12 amerlyq

now the most use tool for me is Unite , here is the link https://github.com/Shougo/unite.vim

wsdjeg avatar Dec 14 '15 14:12 wsdjeg

it is a source tools ,you can create yourself source and ,shown by Unite

wsdjeg avatar Dec 14 '15 14:12 wsdjeg

The map of mappings idea would work, but I wonder if there's a way to make a new filetype yet retain all the quickfix/location list features. If we could do that, then we could just set all the mappings in an autogroup and let people disable that or map over the mappings themselves. That might be more natural, though I've never heard of being able to alias a file type.

losingkeys avatar Feb 13 '16 02:02 losingkeys