From 995fb06f902e071e387e9a6631af914a610beecc Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Sun, 16 Mar 2014 18:53:37 -0300 Subject: [PATCH 01/30] improve highlight doc --- doc/ack.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/ack.txt b/doc/ack.txt index a773a694..8cb42f01 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -104,7 +104,8 @@ Example: g:ackhighlight Default: 0 -Use this option to highlight the searched term +Use this option to highlight the searched term. NOTE: this option does not work +if options or directories are used. Example: > From 2065ff5f9c39272f2dcbb19277718313f012ba48 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Sun, 16 Mar 2014 18:56:58 -0300 Subject: [PATCH 02/30] improve some indentation --- plugin/ack.vim | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/plugin/ack.vim b/plugin/ack.vim index dddc0bb9..5ccbbf6e 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -10,7 +10,7 @@ " Location of the ack utility if !exists("g:ackprg") let s:ackcommand = executable('ack-grep') ? 'ack-grep' : 'ack' - let g:ackprg = s:ackcommand." -H --nocolor --nogroup --column" + let g:ackprg = s:ackcommand . " -H --nocolor --nogroup --column" endif let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) @@ -115,7 +115,7 @@ function! s:Ack(cmd, args) " If highlighting is on, highlight the search keyword. if g:ackhighlight - let @/ = substitute(l:grepargs,'["'']','','g') + let @/ = substitute(l:grepargs, '["'']', '', 'g') set hlsearch end @@ -125,46 +125,46 @@ endfunction function! s:AckFromSearch(cmd, args) let search = getreg('/') " translate vim regular expression to perl regular expression. - let search = substitute(search,'\(\\<\|\\>\)','\\b','g') - call s:Ack(a:cmd, '"' . search .'" '. a:args) + let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g') + call s:Ack(a:cmd, '"' . search . '" ' . a:args) endfunction function! s:GetDocLocations() let dp = '' - for p in split(&rtp,',') - let p = p.'/doc/' + for p in split(&rtp, ',') + let p = p . '/doc/' if isdirectory(p) - let dp = p.'*.txt '.dp + let dp = p . '*.txt ' . dp endif endfor return dp endfunction -function! s:AckHelp(cmd,args) - let args = a:args.' '.s:GetDocLocations() - call s:Ack(a:cmd,args) +function! s:AckHelp(cmd, args) + let args = a:args . ' ' . s:GetDocLocations() + call s:Ack(a:cmd, args) endfunction -function! s:AckWindow(cmd,args) +function! s:AckWindow(cmd, args) let files = tabpagebuflist() " remove duplicated filenames (files appearing in more than one window) - let files = filter(copy(sort(files)),'index(files,v:val,v:key+1)==-1') - call map(files,"bufname(v:val)") + let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1') + call map(files, "bufname(v:val)") " remove unnamed buffers as quickfix (empty strings before shellescape) call filter(files, 'v:val != ""') " expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre) - let files = map(files,"shellescape(fnamemodify(v:val, ':p'))") - let args = a:args.' '.join(files) - call s:Ack(a:cmd,args) + let files = map(files, "shellescape(fnamemodify(v:val, ':p'))") + let args = a:args . ' ' . join(files) + call s:Ack(a:cmd, args) endfunction -command! -bang -nargs=* -complete=file Ack call s:Ack('grep',) +command! -bang -nargs=* -complete=file Ack call s:Ack('grep', ) command! -bang -nargs=* -complete=file AckAdd call s:Ack('grepadd', ) command! -bang -nargs=* -complete=file AckFromSearch call s:AckFromSearch('grep', ) command! -bang -nargs=* -complete=file LAck call s:Ack('lgrep', ) command! -bang -nargs=* -complete=file LAckAdd call s:Ack('lgrepadd', ) command! -bang -nargs=* -complete=file AckFile call s:Ack('grep -g', ) -command! -bang -nargs=* -complete=help AckHelp call s:AckHelp('grep',) -command! -bang -nargs=* -complete=help LAckHelp call s:AckHelp('lgrep',) -command! -bang -nargs=* -complete=help AckWindow call s:AckWindow('grep',) -command! -bang -nargs=* -complete=help LAckWindow call s:AckWindow('lgrep',) +command! -bang -nargs=* -complete=help AckHelp call s:AckHelp('grep', ) +command! -bang -nargs=* -complete=help LAckHelp call s:AckHelp('lgrep', ) +command! -bang -nargs=* -complete=help AckWindow call s:AckWindow('grep', ) +command! -bang -nargs=* -complete=help LAckWindow call s:AckWindow('lgrep', ) From 12e23c0161777052a0e7d6e24d893e4f8270dce1 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Sun, 16 Mar 2014 18:57:22 -0300 Subject: [PATCH 03/30] try to improve highlight --- plugin/ack.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/ack.vim b/plugin/ack.vim index 5ccbbf6e..991199d6 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -115,8 +115,8 @@ function! s:Ack(cmd, args) " If highlighting is on, highlight the search keyword. if g:ackhighlight - let @/ = substitute(l:grepargs, '["'']', '', 'g') set hlsearch + let @/ = substitute(a:args, '["'']', '', 'g') end redraw! From 121f2a925000c4584c2b43e0f843668b698533fa Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 17 Mar 2014 13:12:36 -0300 Subject: [PATCH 04/30] Add, by default, "-s" option. Ack -s option suppress error messages, this way will not fill quickfix window with ack errors. --- plugin/ack.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/ack.vim b/plugin/ack.vim index 323b6171..bc5e9d1e 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -13,7 +13,7 @@ if !exists("g:ackprg") if !executable(s:ackcommand) finish endif - let g:ackprg = s:ackcommand." -H --nocolor --nogroup --column" + let g:ackprg = s:ackcommand."-s -H --nocolor --nogroup --column" endif let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) From bcab76c5991bbbd30216bb1878856822117813ad Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 17 Mar 2014 13:25:00 -0300 Subject: [PATCH 05/30] Move function to autoload. To improve vim's boot process move functions to autoload --- README.md | 2 +- autoload/ack.vim | 122 +++++++++++++++++++++++++++++++++++++ plugin/ack.vim | 152 ++++------------------------------------------- 3 files changed, 133 insertions(+), 143 deletions(-) create mode 100644 autoload/ack.vim diff --git a/README.md b/README.md index 34689c79..c430eabd 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,6 @@ check out the docs for the Perl script 'ack', for obvious reasons: Goals for 1.0: * Improve documentation, list all options and shortcuts -* Use `autoload` directory to define functions, instead of `plugin`. +* ~~Use `autoload` directory to define functions, instead of `plugin`.~~ * Add a help toggle `?`(like NERDTree) * Add option to open all files from result list diff --git a/autoload/ack.vim b/autoload/ack.vim new file mode 100644 index 00000000..4209013d --- /dev/null +++ b/autoload/ack.vim @@ -0,0 +1,122 @@ +function! ack#Ack(cmd, args) + redraw + echo "Searching ..." + + " If no pattern is provided, search for the word under the cursor + if empty(a:args) + let l:grepargs = expand("") + else + let l:grepargs = a:args . join(a:000, ' ') + end + + " Format, used to manage column jump + if a:cmd =~# '-g$' + let g:ackformat="%f" + else + let g:ackformat="%f:%l:%c:%m,%f:%l:%m" + end + + let grepprg_bak=&grepprg + let grepformat_bak=&grepformat + try + let l:ackprg_run = g:ackprg + if a:cmd =~# '-g$' && s:ackprg_version > 2 + " remove arguments that conflict with -g + let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') + end + let &grepprg=l:ackprg_run + let &grepformat=g:ackformat + " NOTE: we escape special chars, but not everything using shellescape to + " allow for passing arguments etc + silent execute a:cmd . " " . escape(l:grepargs, '|#%') + finally + let &grepprg=grepprg_bak + let &grepformat=grepformat_bak + endtry + + if a:cmd =~# '^l' + exe g:ack_lhandler + let l:apply_mappings = g:ack_apply_lmappings + let l:close_cmd = ':lclose' + else + exe g:ack_qhandler + let l:apply_mappings = g:ack_apply_qmappings + let l:close_cmd = ':cclose' + endif + + if l:apply_mappings + if !exists("g:ack_autoclose") || !g:ack_autoclose + exec "nnoremap q " . l:close_cmd + exec "nnoremap t T" + exec "nnoremap T TgTj" + exec "nnoremap o " + exec "nnoremap O :ccl" + exec "nnoremap go j" + exec "nnoremap h K" + exec "nnoremap H Kb" + exec "nnoremap v HbJt" + exec "nnoremap gv HbJ" + else + exec "nnoremap q " . l:close_cmd + exec "nnoremap t T" . l:close_cmd + exec "nnoremap T TgTj" . l:close_cmd + exec "nnoremap o " . l:close_cmd + exec "nnoremap O :ccl" . l:close_cmd + exec "nnoremap go j" . l:close_cmd + exec "nnoremap h K" . l:close_cmd + exec "nnoremap H Kb" . l:close_cmd + exec "nnoremap v HbJt" . l:close_cmd + exec "nnoremap gv HbJ" . l:close_cmd + endif + + " If auto preview in on, remap j and k keys + if exists("g:ackpreview") + exec "nnoremap j j" + exec "nnoremap k k" + endif + endif + + " If highlighting is on, highlight the search keyword. + if g:ackhighlight + set hlsearch + let @/ = substitute(a:args, '["'']', '', 'g') + end + + redraw! +endfunction + +function! ack#AckFromSearch(cmd, args) + let search = getreg('/') + " translate vim regular expression to perl regular expression. + let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g') + call ack#Ack(a:cmd, '"' . search . '" ' . a:args) +endfunction + +function! s:GetDocLocations() + let dp = '' + for p in split(&rtp, ',') + let p = p . '/doc/' + if isdirectory(p) + let dp = p . '*.txt ' . dp + endif + endfor + return dp +endfunction + +function! ack#AckHelp(cmd, args) + let args = a:args . ' ' . s:GetDocLocations() + call ack#Ack(a:cmd, args) +endfunction + +function! ack#AckWindow(cmd, args) + let files = tabpagebuflist() + " remove duplicated filenames (files appearing in more than one window) + let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1') + call map(files, "bufname(v:val)") + " remove unnamed buffers as quickfix (empty strings before shellescape) + call filter(files, 'v:val != ""') + " expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre) + let files = map(files, "shellescape(fnamemodify(v:val, ':p'))") + let args = a:args . ' ' . join(files) + call ack#Ack(a:cmd, args) +endfunction diff --git a/plugin/ack.vim b/plugin/ack.vim index bc5e9d1e..5665b280 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -1,12 +1,3 @@ -" NOTE: You must, of course, install the ack script -" in your path. -" On Debian / Ubuntu: -" sudo apt-get install ack-grep -" With MacPorts: -" sudo port install p5-app-ack -" With Homebrew: -" brew install ack - " Location of the ack utility if !exists("g:ackprg") let s:ackcommand = executable('ack-grep') ? 'ack-grep' : 'ack' @@ -38,136 +29,13 @@ if !exists("g:ackhighlight") let g:ackhighlight = 0 end -function! s:Ack(cmd, args) - redraw - echo "Searching ..." - - " If no pattern is provided, search for the word under the cursor - if empty(a:args) - let l:grepargs = expand("") - else - let l:grepargs = a:args . join(a:000, ' ') - end - - " Format, used to manage column jump - if a:cmd =~# '-g$' - let g:ackformat="%f" - else - let g:ackformat="%f:%l:%c:%m,%f:%l:%m" - end - - let grepprg_bak=&grepprg - let grepformat_bak=&grepformat - try - let l:ackprg_run = g:ackprg - if a:cmd =~# '-g$' && s:ackprg_version > 2 - " remove arguments that conflict with -g - let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') - end - let &grepprg=l:ackprg_run - let &grepformat=g:ackformat - " NOTE: we escape special chars, but not everything using shellescape to - " allow for passing arguments etc - silent execute a:cmd . " " . escape(l:grepargs, '|#%') - finally - let &grepprg=grepprg_bak - let &grepformat=grepformat_bak - endtry - - if a:cmd =~# '^l' - exe g:ack_lhandler - let l:apply_mappings = g:ack_apply_lmappings - let l:close_cmd = ':lclose' - else - exe g:ack_qhandler - let l:apply_mappings = g:ack_apply_qmappings - let l:close_cmd = ':cclose' - endif - - if l:apply_mappings - if !exists("g:ack_autoclose") || !g:ack_autoclose - exec "nnoremap q " . l:close_cmd - exec "nnoremap t T" - exec "nnoremap T TgTj" - exec "nnoremap o " - exec "nnoremap O :ccl" - exec "nnoremap go j" - exec "nnoremap h K" - exec "nnoremap H Kb" - exec "nnoremap v HbJt" - exec "nnoremap gv HbJ" - else - exec "nnoremap q " . l:close_cmd - exec "nnoremap t T" . l:close_cmd - exec "nnoremap T TgTj" . l:close_cmd - exec "nnoremap o " . l:close_cmd - exec "nnoremap O :ccl" . l:close_cmd - exec "nnoremap go j" . l:close_cmd - exec "nnoremap h K" . l:close_cmd - exec "nnoremap H Kb" . l:close_cmd - exec "nnoremap v HbJt" . l:close_cmd - exec "nnoremap gv HbJ" . l:close_cmd - endif - - " If auto preview in on, remap j and k keys - if exists("g:ackpreview") - exec "nnoremap j j" - exec "nnoremap k k" - endif - endif - - " If highlighting is on, highlight the search keyword. - if g:ackhighlight - set hlsearch - let @/ = substitute(a:args, '["'']', '', 'g') - end - - redraw! -endfunction - -function! s:AckFromSearch(cmd, args) - let search = getreg('/') - " translate vim regular expression to perl regular expression. - let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g') - call s:Ack(a:cmd, '"' . search . '" ' . a:args) -endfunction - -function! s:GetDocLocations() - let dp = '' - for p in split(&rtp, ',') - let p = p . '/doc/' - if isdirectory(p) - let dp = p . '*.txt ' . dp - endif - endfor - return dp -endfunction - -function! s:AckHelp(cmd, args) - let args = a:args . ' ' . s:GetDocLocations() - call s:Ack(a:cmd, args) -endfunction - -function! s:AckWindow(cmd, args) - let files = tabpagebuflist() - " remove duplicated filenames (files appearing in more than one window) - let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1') - call map(files, "bufname(v:val)") - " remove unnamed buffers as quickfix (empty strings before shellescape) - call filter(files, 'v:val != ""') - " expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre) - let files = map(files, "shellescape(fnamemodify(v:val, ':p'))") - let args = a:args . ' ' . join(files) - call s:Ack(a:cmd, args) -endfunction - -command! -bang -nargs=* -complete=file Ack call s:Ack('grep', ) -command! -bang -nargs=* -complete=file AckAdd call s:Ack('grepadd', ) -command! -bang -nargs=* -complete=file AckFromSearch call s:AckFromSearch('grep', ) -command! -bang -nargs=* -complete=file LAck call s:Ack('lgrep', ) -command! -bang -nargs=* -complete=file LAckAdd call s:Ack('lgrepadd', ) -command! -bang -nargs=* -complete=file AckFile call s:Ack('grep -g', ) -command! -bang -nargs=* -complete=help AckHelp call s:AckHelp('grep', ) -command! -bang -nargs=* -complete=help LAckHelp call s:AckHelp('lgrep', ) -command! -bang -nargs=* -complete=help AckWindow call s:AckWindow('grep', ) -command! -bang -nargs=* -complete=help LAckWindow call s:AckWindow('lgrep', ) +command! -bang -nargs=* -complete=file Ack call ack#Ack('grep', ) +command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd', ) +command! -bang -nargs=* -complete=file AckFromSearch call ack#AckFromSearch('grep', ) +command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep', ) +command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd', ) +command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep -g', ) +command! -bang -nargs=* -complete=help AckHelp call ack#AckHelp('grep', ) +command! -bang -nargs=* -complete=help LAckHelp call ack#AckHelp('lgrep', ) +command! -bang -nargs=* -complete=help AckWindow call ack#AckWindow('grep', ) +command! -bang -nargs=* -complete=help LAckWindow call ack#AckWindow('lgrep', ) From 317c6b3f6c1153e916a11e075c20436506f3a19d Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 17 Mar 2014 18:16:16 -0300 Subject: [PATCH 06/30] remove some duplication --- autoload/ack.vim | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 4209013d..c85605f6 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -34,6 +34,13 @@ function! ack#Ack(cmd, args) let &grepformat=grepformat_bak endtry + call apply_maps(a:cmd) + call highlight(a:args) + + redraw! +endfunction + +function! s:apply_maps(cmd) if a:cmd =~# '^l' exe g:ack_lhandler let l:apply_mappings = g:ack_apply_lmappings @@ -44,45 +51,42 @@ function! ack#Ack(cmd, args) let l:close_cmd = ':cclose' endif + let l:maps = { + \ "q": l:close_cmd, + \ "t": "T", + \ "T": "TgTj", + \ "o": "", + \ "O": ":ccl", + \ "go": "j", + \ "h": "K", + \ "H": "Kb", + \ "v": "HbJt", + \ "gv": "HbJ" } + if l:apply_mappings if !exists("g:ack_autoclose") || !g:ack_autoclose - exec "nnoremap q " . l:close_cmd - exec "nnoremap t T" - exec "nnoremap T TgTj" - exec "nnoremap o " - exec "nnoremap O :ccl" - exec "nnoremap go j" - exec "nnoremap h K" - exec "nnoremap H Kb" - exec "nnoremap v HbJt" - exec "nnoremap gv HbJ" + for key_map in items(l:maps) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) + endfor else - exec "nnoremap q " . l:close_cmd - exec "nnoremap t T" . l:close_cmd - exec "nnoremap T TgTj" . l:close_cmd - exec "nnoremap o " . l:close_cmd - exec "nnoremap O :ccl" . l:close_cmd - exec "nnoremap go j" . l:close_cmd - exec "nnoremap h K" . l:close_cmd - exec "nnoremap H Kb" . l:close_cmd - exec "nnoremap v HbJt" . l:close_cmd - exec "nnoremap gv HbJ" . l:close_cmd + for key_map in items(l:maps) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . l:close_cmd) + endfor endif " If auto preview in on, remap j and k keys if exists("g:ackpreview") - exec "nnoremap j j" - exec "nnoremap k k" + execute "nnoremap j j" + execute "nnoremap k k" endif endif +endfunction - " If highlighting is on, highlight the search keyword. +function! s:highlight(args) if g:ackhighlight set hlsearch let @/ = substitute(a:args, '["'']', '', 'g') end - - redraw! endfunction function! ack#AckFromSearch(cmd, args) From 7547a700519284e7a32ac1d2d9ee6b671ce76da3 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 18 Mar 2014 09:28:26 -0300 Subject: [PATCH 07/30] fix highlight, force to highlight the searched term --- autoload/ack.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/ack.vim b/autoload/ack.vim index c85605f6..c9dcfe8a 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -86,6 +86,7 @@ function! s:highlight(args) if g:ackhighlight set hlsearch let @/ = substitute(a:args, '["'']', '', 'g') + call feedkeys(":let &hlsearch=1\", "n") end endfunction From 0a8a0eb8462cf92830a2bad7de9d58812e66824a Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 18 Mar 2014 09:42:08 -0300 Subject: [PATCH 08/30] fix maps to work only on quickfix window --- autoload/ack.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index c9dcfe8a..39c9f5b8 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -66,18 +66,18 @@ function! s:apply_maps(cmd) if l:apply_mappings if !exists("g:ack_autoclose") || !g:ack_autoclose for key_map in items(l:maps) - execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor else for key_map in items(l:maps) - execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . l:close_cmd) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . l:close_cmd) endfor endif " If auto preview in on, remap j and k keys if exists("g:ackpreview") - execute "nnoremap j j" - execute "nnoremap k k" + execute "nnoremap j j" + execute "nnoremap k k" endif endif endfunction From e39b0d81cfafa2558824b85f1680edabd17e77e4 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 18 Mar 2014 15:01:29 -0300 Subject: [PATCH 09/30] some code improvements --- autoload/ack.vim | 66 ++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 39c9f5b8..704acf0c 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -8,24 +8,25 @@ function! ack#Ack(cmd, args) else let l:grepargs = a:args . join(a:000, ' ') end + let l:ackprg_run = g:ackprg " Format, used to manage column jump if a:cmd =~# '-g$' let g:ackformat="%f" + if s:ackprg_version > 2 + " remove arguments that conflict with -g + let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') + endif else let g:ackformat="%f:%l:%c:%m,%f:%l:%m" - end + endif + + let grepprg_bak = &grepprg + let grepformat_bak = &grepformat + let &grepprg=l:ackprg_run + let &grepformat=g:ackformat - let grepprg_bak=&grepprg - let grepformat_bak=&grepformat try - let l:ackprg_run = g:ackprg - if a:cmd =~# '-g$' && s:ackprg_version > 2 - " remove arguments that conflict with -g - let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') - end - let &grepprg=l:ackprg_run - let &grepformat=g:ackformat " NOTE: we escape special chars, but not everything using shellescape to " allow for passing arguments etc silent execute a:cmd . " " . escape(l:grepargs, '|#%') @@ -34,25 +35,30 @@ function! ack#Ack(cmd, args) let &grepformat=grepformat_bak endtry - call apply_maps(a:cmd) + if a:cmd =~# '^l' + let s:handler = g:ack_lhandler + let s:apply_mappings = g:ack_apply_lmappings + let s:close_cmd = ':lclose' + else + let s:handler = g:ack_qhandler + let s:apply_mappings = g:ack_apply_qmappings + let s:close_cmd = ':cclose' + endif + + call show_results(a:cmd) call highlight(a:args) redraw! endfunction -function! s:apply_maps(cmd) - if a:cmd =~# '^l' - exe g:ack_lhandler - let l:apply_mappings = g:ack_apply_lmappings - let l:close_cmd = ':lclose' - else - exe g:ack_qhandler - let l:apply_mappings = g:ack_apply_qmappings - let l:close_cmd = ':cclose' - endif +function! s:show_results(cmd) + execute s:handler + call apply_maps() +endfunction - let l:maps = { - \ "q": l:close_cmd, +function! s:apply_maps() + let s:maps = { + \ "q": s:close_cmd, \ "t": "T", \ "T": "TgTj", \ "o": "", @@ -63,19 +69,18 @@ function! s:apply_maps(cmd) \ "v": "HbJt", \ "gv": "HbJ" } - if l:apply_mappings + if s:apply_mappings if !exists("g:ack_autoclose") || !g:ack_autoclose - for key_map in items(l:maps) + for key_map in items(s:maps) execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor else - for key_map in items(l:maps) - execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . l:close_cmd) + for key_map in items(s:maps) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . s:close_cmd) endfor endif - " If auto preview in on, remap j and k keys - if exists("g:ackpreview") + if exists("g:ackpreview") " if auto preview in on, remap j and k keys execute "nnoremap j j" execute "nnoremap k k" endif @@ -87,7 +92,7 @@ function! s:highlight(args) set hlsearch let @/ = substitute(a:args, '["'']', '', 'g') call feedkeys(":let &hlsearch=1\", "n") - end + endif endfunction function! ack#AckFromSearch(cmd, args) @@ -105,6 +110,7 @@ function! s:GetDocLocations() let dp = p . '*.txt ' . dp endif endfor + return dp endfunction From 0df84ec9616f6f393289e1165ea721a76f7b46f1 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 18 Mar 2014 22:27:10 -0300 Subject: [PATCH 10/30] update Goals for 1.0 in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c430eabd..02594fa1 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,6 @@ check out the docs for the Perl script 'ack', for obvious reasons: Goals for 1.0: * Improve documentation, list all options and shortcuts -* ~~Use `autoload` directory to define functions, instead of `plugin`.~~ +* ~~Use `autoload` directory to define functions, instead of `plugin`.~~ DONE * Add a help toggle `?`(like NERDTree) -* Add option to open all files from result list +* ~~Add option to open all files from result list~~ WILL NOT BE IMPLEMENTED From c38cfede4f72512c8a45c990cd26e07698384d98 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Thu, 20 Mar 2014 23:34:56 -0300 Subject: [PATCH 11/30] autofolding results by filename --- ftplugin/qf.vim | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ftplugin/qf.vim diff --git a/ftplugin/qf.vim b/ftplugin/qf.vim new file mode 100644 index 00000000..f053d12c --- /dev/null +++ b/ftplugin/qf.vim @@ -0,0 +1,4 @@ +setlocal foldlevel=0 +setlocal foldmethod=expr +setlocal foldexpr=matchstr(getline(v:lnum),'^[^\|]\\+')==#matchstr(getline(v:lnum+1),'^[^\|]\\+')?1:'<1' +setlocal foldenable From 689d77cb0d138894aaefa3593084c7c80630b44a Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 21 Mar 2014 10:01:44 -0300 Subject: [PATCH 12/30] autoopen and autoclose folds --- ftplugin/qf.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ftplugin/qf.vim b/ftplugin/qf.vim index f053d12c..3ff84ae1 100644 --- a/ftplugin/qf.vim +++ b/ftplugin/qf.vim @@ -2,3 +2,5 @@ setlocal foldlevel=0 setlocal foldmethod=expr setlocal foldexpr=matchstr(getline(v:lnum),'^[^\|]\\+')==#matchstr(getline(v:lnum+1),'^[^\|]\\+')?1:'<1' setlocal foldenable +setlocal foldclose=all +setlocal foldopen=all From 35ca67401847e9c2850715ee1d32c804cc335bb2 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 21 Mar 2014 14:40:13 -0300 Subject: [PATCH 13/30] add auto fold as option --- doc/ack.txt | 17 ++++++++++++++++- ftplugin/qf.vim | 15 +++++++++------ plugin/ack.vim | 6 +++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/doc/ack.txt b/doc/ack.txt index 8cb42f01..94c339ee 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -109,7 +109,22 @@ if options or directories are used. Example: > - let g:ackhighlight + let g:ackhighlight = 1 +< + + *g:ack_autofold_results* + +g:ack_autofold_results +Default: 0 + +Use this option to fold the results in quickfix by file name. Only the current +fold will be open by default and while you press 'j' and 'k' to move between the +results if you hit other fold the last one will be closed and the current will +be open. + +Example: +> + let g:ack_autofold_results = 1 < ============================================================================== diff --git a/ftplugin/qf.vim b/ftplugin/qf.vim index 3ff84ae1..7da45a4c 100644 --- a/ftplugin/qf.vim +++ b/ftplugin/qf.vim @@ -1,6 +1,9 @@ -setlocal foldlevel=0 -setlocal foldmethod=expr -setlocal foldexpr=matchstr(getline(v:lnum),'^[^\|]\\+')==#matchstr(getline(v:lnum+1),'^[^\|]\\+')?1:'<1' -setlocal foldenable -setlocal foldclose=all -setlocal foldopen=all +if g:ack_autofold_results + setlocal foldlevel=0 + setlocal foldmethod=expr + setlocal foldexpr=matchstr(getline(v:lnum),'^[^\|]\\+')==#matchstr(getline(v:lnum+1),'^[^\|]\\+')?1:'<1' + setlocal foldenable + setlocal foldclose=all + setlocal foldopen=all + nnoremap j jzz +endif diff --git a/plugin/ack.vim b/plugin/ack.vim index 5665b280..f140382e 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -27,7 +27,11 @@ endif if !exists("g:ackhighlight") let g:ackhighlight = 0 -end +endif + +if !exists("g:ack_autofold_results") + let g:ack_autofold_results = 0 +endif command! -bang -nargs=* -complete=file Ack call ack#Ack('grep', ) command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd', ) From 6f57542f6df2bb1febea36465da07349f0802c6b Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 21 Mar 2014 14:42:42 -0300 Subject: [PATCH 14/30] move Roadmap to a Changelog --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 02594fa1..ce03e38d 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,12 @@ provides just enough reference to get you going. I also highly recommend you check out the docs for the Perl script 'ack', for obvious reasons: [ack - grep-like text finder](http://beyondgrep.com/). -## RoadMap +## Changelog -Goals for 1.0: +### 1.0 +* Started a Changelog +* Use `autoload` directory to define functions, instead of `plugin`. +* Added option to auto fold the results(`g:ack_autofold_results`) * Improve documentation, list all options and shortcuts -* ~~Use `autoload` directory to define functions, instead of `plugin`.~~ DONE * Add a help toggle `?`(like NERDTree) -* ~~Add option to open all files from result list~~ WILL NOT BE IMPLEMENTED From d09763e4a2ea3184cdbb9743cfea0fb7f0ebda4c Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Sun, 23 Mar 2014 20:54:13 -0300 Subject: [PATCH 15/30] add documentation for g:ackpreview --- doc/ack.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/ack.txt b/doc/ack.txt index 94c339ee..907c69ca 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -127,6 +127,18 @@ Example: let g:ack_autofold_results = 1 < + *g:ackpreview* + +g:ackpreview +Default: 0 + +Use this option to automagically open the file with 'j' or 'k'. + +Example: +> + let g:ackpreview = 1 +< + ============================================================================== MAPPINGS *ack-mappings* From f0469c3587925ab88ec95b8980fa65ae20a89f62 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 24 Mar 2014 18:45:18 -0300 Subject: [PATCH 16/30] do not blow without ack or ack-grep --- plugin/ack.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/ack.vim b/plugin/ack.vim index f140382e..eeaa8bc6 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -1,10 +1,14 @@ " Location of the ack utility if !exists("g:ackprg") - let s:ackcommand = executable('ack-grep') ? 'ack-grep' : 'ack' - if !executable(s:ackcommand) + let s:ack_default_options = "-s -H --nocolor --nogroup --column" + if executable('ack-grep') + let g:ackprg = "ack-grep" + elseif executable('ack') + let g:ackprg = "ack" + else finish endif - let g:ackprg = s:ackcommand."-s -H --nocolor --nogroup --column" + let g:ackprg .= s:ack_default_options endif let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) From b6799f1913b30f0799ac12c491739bb0d4f9ccfe Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 24 Mar 2014 18:45:30 -0300 Subject: [PATCH 17/30] only apply maps when found results --- autoload/ack.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 704acf0c..f985617e 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -69,7 +69,7 @@ function! s:apply_maps() \ "v": "HbJt", \ "gv": "HbJ" } - if s:apply_mappings + if s:apply_mappings && &ft == "qf" if !exists("g:ack_autoclose") || !g:ack_autoclose for key_map in items(s:maps) execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) From b9b8c0a06e9a8cf6d8b75e3235af024851142171 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 24 Mar 2014 23:50:29 -0300 Subject: [PATCH 18/30] using v:hlsearch instead of &hlsearch(hlsearch improvements) --- autoload/ack.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index f985617e..60c31c0e 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -89,9 +89,9 @@ endfunction function! s:highlight(args) if g:ackhighlight - set hlsearch + setlocal hlsearch let @/ = substitute(a:args, '["'']', '', 'g') - call feedkeys(":let &hlsearch=1\", "n") + call feedkeys(":let v:hlsearch=1 \| echo \", "n") endif endfunction From 41344d8002ae78a560c9403c6b3d7c6ded230f7c Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 25 Mar 2014 09:18:27 -0300 Subject: [PATCH 19/30] put space between ackprg and ack_default_options :bomb: Thank's @kamelzcs fixes #110 Conflicts: plugin/ack.vim --- plugin/ack.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/ack.vim b/plugin/ack.vim index eeaa8bc6..e21cf25a 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -1,14 +1,13 @@ " Location of the ack utility if !exists("g:ackprg") - let s:ack_default_options = "-s -H --nocolor --nogroup --column" - if executable('ack-grep') - let g:ackprg = "ack-grep" - elseif executable('ack') + if executable('ack') let g:ackprg = "ack" + elseif executable('ack-grep') + let g:ackprg = "ack-grep" else finish endif - let g:ackprg .= s:ack_default_options + let g:ackprg .= " -s -H --nocolor --nogroup --column" endif let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) From 92363f2d2f3e949f4f96be453d0740265511b530 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 25 Mar 2014 09:32:44 -0300 Subject: [PATCH 20/30] remove some duplicated spaces among of code --- autoload/ack.vim | 6 +++--- plugin/ack.vim | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 60c31c0e..13302bf5 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -91,15 +91,15 @@ function! s:highlight(args) if g:ackhighlight setlocal hlsearch let @/ = substitute(a:args, '["'']', '', 'g') - call feedkeys(":let v:hlsearch=1 \| echo \", "n") + call feedkeys(":let v:hlsearch=1 \| echo \", "n") endif endfunction function! ack#AckFromSearch(cmd, args) - let search = getreg('/') + let search = getreg('/') " translate vim regular expression to perl regular expression. let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g') - call ack#Ack(a:cmd, '"' . search . '" ' . a:args) + call ack#Ack(a:cmd, '"' . search . '" ' . a:args) endfunction function! s:GetDocLocations() diff --git a/plugin/ack.vim b/plugin/ack.vim index e21cf25a..0bc8d88f 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -10,7 +10,7 @@ if !exists("g:ackprg") let g:ackprg .= " -s -H --nocolor --nogroup --column" endif -let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) +let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) if !exists("g:ack_apply_qmappings") let g:ack_apply_qmappings = !exists("g:ack_qhandler") From 393bfb88d402424e72e047cad6b4a021517b5f82 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 25 Mar 2014 09:42:57 -0300 Subject: [PATCH 21/30] improve documentation, add all options --- README.md | 4 ++-- autoload/ack.vim | 2 +- doc/ack.txt | 52 +++++++++++++++++++++++++++++++++++++++--------- plugin/ack.vim | 4 ++++ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ce03e38d..95b9e23a 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ check out the docs for the Perl script 'ack', for obvious reasons: ### 1.0 -* Started a Changelog +* Start to use a Changelog * Use `autoload` directory to define functions, instead of `plugin`. -* Added option to auto fold the results(`g:ack_autofold_results`) +* Add option to auto fold the results(`g:ack_autofold_results`) * Improve documentation, list all options and shortcuts * Add a help toggle `?`(like NERDTree) diff --git a/autoload/ack.vim b/autoload/ack.vim index 13302bf5..496147fe 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -70,7 +70,7 @@ function! s:apply_maps() \ "gv": "HbJ" } if s:apply_mappings && &ft == "qf" - if !exists("g:ack_autoclose") || !g:ack_autoclose + if !g:ack_autoclose for key_map in items(s:maps) execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor diff --git a/doc/ack.txt b/doc/ack.txt index 907c69ca..24cd6b72 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -76,8 +76,8 @@ CONFIGURATION *ack-configuration* *g:ackprg* g:ackprg -Default for ubuntu: "ack-grep -H --nocolor --nogroup --column" -Default for other systems: "ack -H --nocolor --nogroup --column" +Default for ubuntu: "ack-grep -s -H --nocolor --nogroup --column" +Default for other systems: "ack -s -H --nocolor --nogroup --column" Use this option to specify the ack command and its options @@ -87,16 +87,38 @@ Example: \ "ack -H --nocolor --nogroup --column --smart-case --follow" < - *g:ack_autoclose* -g:ack_autoclose -Default: 0 + *g:ack_apply_qmappings* +g:ack_apply_qmappings +Default: 1 -Use this option to specify whether to close the quickfix window after -using any of the shortcuts. +This option enable mappings on quickview window. -Example: + *g:ack_apply_lmappings* +g:ack_apply_lmappings +Default: 1 + +This option enable mappings on Location list window. + + *g:ack_qhandler* +g:ack_qhandler +Default: "botright copen" + +Command to open the quickview window. + +If you want to open a quickview window with 30 lines you can do: > - let g:ack_autoclose = 1 + let g:ack_qhandler = "botright copen 30" +< + + *g:ack_lhandler* +g:ack_lhandler +Default: "botright lopen" + +Command to open the Location list window. + +If you want to open a Location list window with 30 lines you can do: +> + let g:ack_lhandler = "botright lopen 30" < *g:ackhighlight* @@ -112,6 +134,18 @@ Example: let g:ackhighlight = 1 < + *g:ack_autoclose* +g:ack_autoclose +Default: 0 + +Use this option to specify whether to close the quickfix window after +using any of the shortcuts. + +Example: +> + let g:ack_autoclose = 1 +< + *g:ack_autofold_results* g:ack_autofold_results diff --git a/plugin/ack.vim b/plugin/ack.vim index 0bc8d88f..9a50c1a3 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -32,6 +32,10 @@ if !exists("g:ackhighlight") let g:ackhighlight = 0 endif +if !exists("g:ack_autoclose") + let g:ack_autoclose = 0 +endif + if !exists("g:ack_autofold_results") let g:ack_autofold_results = 0 endif From 5256a8530108b95ddecaeb35eaea8d2933a63059 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Fri, 28 Mar 2014 22:16:07 -0300 Subject: [PATCH 22/30] improve highlight option to work with directories and quotes --- README.md | 1 + autoload/ack.vim | 10 ++++++---- doc/ack.txt | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 95b9e23a..fd73dde3 100644 --- a/README.md +++ b/README.md @@ -80,4 +80,5 @@ check out the docs for the Perl script 'ack', for obvious reasons: * Use `autoload` directory to define functions, instead of `plugin`. * Add option to auto fold the results(`g:ack_autofold_results`) * Improve documentation, list all options and shortcuts +* Improve highlight option to work when passes directories or use quotes. * Add a help toggle `?`(like NERDTree) diff --git a/autoload/ack.vim b/autoload/ack.vim index 496147fe..a9198419 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -88,11 +88,13 @@ function! s:apply_maps() endfunction function! s:highlight(args) - if g:ackhighlight - setlocal hlsearch - let @/ = substitute(a:args, '["'']', '', 'g') - call feedkeys(":let v:hlsearch=1 \| echo \", "n") + if !g:ackhighlight + return endif + + let @/ = matchstr(a:args, "\\v\\w+\>|['\"]\\zs[^\"]+\\ze['\"]") + setlocal hlsearch + call feedkeys(":let v:hlsearch=1 \| echo \", "n") endfunction function! ack#AckFromSearch(cmd, args) diff --git a/doc/ack.txt b/doc/ack.txt index 24cd6b72..8e9faab5 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -126,8 +126,7 @@ If you want to open a Location list window with 30 lines you can do: g:ackhighlight Default: 0 -Use this option to highlight the searched term. NOTE: this option does not work -if options or directories are used. +Use this option to highlight the searched term. Example: > From 69bc47958ce6bcdd0a5912de13ac4a742a6dd736 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Mon, 31 Mar 2014 17:36:59 -0300 Subject: [PATCH 23/30] Remove support to ack 1.x --- README.md | 1 + autoload/ack.vim | 5 +---- plugin/ack.vim | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fd73dde3..a8a9db6f 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ check out the docs for the Perl script 'ack', for obvious reasons: ### 1.0 +* Remove support to ack 1.x * Start to use a Changelog * Use `autoload` directory to define functions, instead of `plugin`. * Add option to auto fold the results(`g:ack_autofold_results`) diff --git a/autoload/ack.vim b/autoload/ack.vim index a9198419..d9ce45dd 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -13,10 +13,7 @@ function! ack#Ack(cmd, args) " Format, used to manage column jump if a:cmd =~# '-g$' let g:ackformat="%f" - if s:ackprg_version > 2 - " remove arguments that conflict with -g - let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') - endif + let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g') else let g:ackformat="%f:%l:%c:%m,%f:%l:%m" endif diff --git a/plugin/ack.vim b/plugin/ack.vim index 9a50c1a3..e4918e0b 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -10,8 +10,6 @@ if !exists("g:ackprg") let g:ackprg .= " -s -H --nocolor --nogroup --column" endif -let s:ackprg_version = eval(matchstr(system(g:ackprg . " --version"), '[0-9.]\+')) - if !exists("g:ack_apply_qmappings") let g:ack_apply_qmappings = !exists("g:ack_qhandler") endif From e691eddb0759bcce332f27c6cc7fdaee3c2261b7 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Wed, 2 Apr 2014 09:44:43 -0300 Subject: [PATCH 24/30] back with information about special chars on readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index a8a9db6f..4fa41436 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,12 @@ provides just enough reference to get you going. I also highly recommend you check out the docs for the Perl script 'ack', for obvious reasons: [ack - grep-like text finder](http://beyondgrep.com/). +### Gotchas + +Some characters have special meaning, and need to be escaped your search +pattern. For instance, '#'. You have to escape it like this :Ack '\\\#define +foo' to search for #define foo. (From blueyed in issue #5.) + ## Changelog ### 1.0 From a1923662053adcfcd4574a56bcb052c918be257a Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Thu, 3 Apr 2014 15:56:53 -0300 Subject: [PATCH 25/30] fix highlight to work when Ack does not receive any arguments --- autoload/ack.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index d9ce45dd..6060f152 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -43,7 +43,7 @@ function! ack#Ack(cmd, args) endif call show_results(a:cmd) - call highlight(a:args) + call highlight(l:grepargs) redraw! endfunction From f372f6932002652620ca98e613e2986a9337f53e Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Thu, 10 Apr 2014 23:43:36 -0300 Subject: [PATCH 26/30] add a global variable with mappings --- README.md | 1 + autoload/ack.vim | 14 ++------------ doc/ack.txt | 20 ++++++++++++++++++++ plugin/ack.vim | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4fa41436..7e474f9e 100644 --- a/README.md +++ b/README.md @@ -88,4 +88,5 @@ foo' to search for #define foo. (From blueyed in issue #5.) * Add option to auto fold the results(`g:ack_autofold_results`) * Improve documentation, list all options and shortcuts * Improve highlight option to work when passes directories or use quotes. +* Add g:ack_mapping * Add a help toggle `?`(like NERDTree) diff --git a/autoload/ack.vim b/autoload/ack.vim index 6060f152..f44b3dba 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -54,21 +54,11 @@ function! s:show_results(cmd) endfunction function! s:apply_maps() - let s:maps = { - \ "q": s:close_cmd, - \ "t": "T", - \ "T": "TgTj", - \ "o": "", - \ "O": ":ccl", - \ "go": "j", - \ "h": "K", - \ "H": "Kb", - \ "v": "HbJt", - \ "gv": "HbJ" } + let g:ack_mappings.q = s:close_cmd if s:apply_mappings && &ft == "qf" if !g:ack_autoclose - for key_map in items(s:maps) + for key_map in items(g:ack_mappings) execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor else diff --git a/doc/ack.txt b/doc/ack.txt index 8e9faab5..ff27e726 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -99,6 +99,26 @@ Default: 1 This option enable mappings on Location list window. + *g:ack_mappings* +g:ack_mappings +Default: { + \ "t": "T", + \ "T": "TgTj", + \ "o": "", + \ "O": ":ccl", + \ "go": "j", + \ "h": "K", + \ "H": "Kb", + \ "v": "HbJt", + \ "gv": "HbJ" } + +This option list all maps create on quickfix/Location list window. + +Example, if you want to open the result in the middle of the screen: +> + let g:ack_mappings = { "o": "zz" } +< + *g:ack_qhandler* g:ack_qhandler Default: "botright copen" diff --git a/plugin/ack.vim b/plugin/ack.vim index e4918e0b..d89d236e 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -18,6 +18,23 @@ if !exists("g:ack_apply_lmappings") let g:ack_apply_lmappings = !exists("g:ack_lhandler") endif +let s:ack_mappings = { + \ "t": "T", + \ "T": "TgTj", + \ "o": "", + \ "O": ":ccl", + \ "go": "j", + \ "h": "K", + \ "H": "Kb", + \ "v": "HbJt", + \ "gv": "HbJ" } + +if exists("g:ack_mappings") + let g:ack_mappings = extend(s:ack_mappings, g:ack_mappings) +else + let g:ack_mappings = s:ack_mappings +endif + if !exists("g:ack_qhandler") let g:ack_qhandler = "botright copen" endif From edd0b7f6fca0b2a65e13bd836b05103a1a0d81de Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 15 Apr 2014 23:17:33 -0300 Subject: [PATCH 27/30] backport of 5495f98 --- autoload/ack.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index f44b3dba..49e8fee2 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -62,9 +62,10 @@ function! s:apply_maps() execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor else - for key_map in items(s:maps) + for key_map in items(g:ack_mappings) execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . s:close_cmd) endfor + execute "nnoremap " . s:close_cmd endif if exists("g:ackpreview") " if auto preview in on, remap j and k keys From a0399104b57b0de444cb8e77244cbd8eb4a44284 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Tue, 15 Apr 2014 23:24:38 -0300 Subject: [PATCH 28/30] Add g:ack_default_options Now users can customize ack default options independently of g:ackprg --- README.md | 1 + plugin/ack.vim | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e474f9e..d9dbb929 100644 --- a/README.md +++ b/README.md @@ -89,4 +89,5 @@ foo' to search for #define foo. (From blueyed in issue #5.) * Improve documentation, list all options and shortcuts * Improve highlight option to work when passes directories or use quotes. * Add g:ack_mapping +* Add g:ack_default_options * Add a help toggle `?`(like NERDTree) diff --git a/plugin/ack.vim b/plugin/ack.vim index d89d236e..e5d0507b 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -1,3 +1,7 @@ +if !exists("g:ack_default_options") + let g:ack_default_options = " -s -H --nocolor --nogroup --column" +endif + " Location of the ack utility if !exists("g:ackprg") if executable('ack') @@ -7,7 +11,7 @@ if !exists("g:ackprg") else finish endif - let g:ackprg .= " -s -H --nocolor --nogroup --column" + let g:ackprg .= g:ack_default_options endif if !exists("g:ack_apply_qmappings") From 49c0612d752df013ad8d26d92ecd2673c1729f78 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Wed, 16 Apr 2014 14:29:00 -0300 Subject: [PATCH 29/30] add a quick help. closes #64 --- autoload/ack.vim | 32 ++++++++++++++++++++++++++------ doc/ack_quick_help.txt | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 doc/ack_quick_help.txt diff --git a/autoload/ack.vim b/autoload/ack.vim index 49e8fee2..ff8d8eb6 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -42,13 +42,13 @@ function! ack#Ack(cmd, args) let s:close_cmd = ':cclose' endif - call show_results(a:cmd) + call ack#show_results() call highlight(l:grepargs) redraw! endfunction -function! s:show_results(cmd) +function! ack#show_results() execute s:handler call apply_maps() endfunction @@ -56,16 +56,18 @@ endfunction function! s:apply_maps() let g:ack_mappings.q = s:close_cmd + execute "nnoremap ? :call ack#quick_help()" + if s:apply_mappings && &ft == "qf" - if !g:ack_autoclose + if g:ack_autoclose for key_map in items(g:ack_mappings) - execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . s:close_cmd) endfor + execute "nnoremap " . s:close_cmd else for key_map in items(g:ack_mappings) - execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1) . s:close_cmd) + execute printf("nnoremap %s %s", get(key_map, 0), get(key_map, 1)) endfor - execute "nnoremap " . s:close_cmd endif if exists("g:ackpreview") " if auto preview in on, remap j and k keys @@ -75,6 +77,24 @@ function! s:apply_maps() endif endfunction +function! ack#quick_help() + execute "edit " . globpath(&rtp, "doc/ack_quick_help.txt") + + silent normal gg + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal noswapfile + setlocal nobuflisted + setlocal nomodifiable + setlocal filetype=help + setlocal nonumber + setlocal norelativenumber + setlocal nowrap + setlocal foldlevel=20 + setlocal foldmethod=diff + nnoremap ? :q!:call ack#show_results() +endfunction + function! s:highlight(args) if !g:ackhighlight return diff --git a/doc/ack_quick_help.txt b/doc/ack_quick_help.txt new file mode 100644 index 00000000..5c52f6cb --- /dev/null +++ b/doc/ack_quick_help.txt @@ -0,0 +1,14 @@ +==== ack.vim quick help =============== + + *?:* Show this help + *t:* Open in a new tab + *T:* Open in a new tab silently + *o:* Open + *O:* Open and close result window + *go:* Preview + *h:* Horizontal open + *H:* Horizontal open silently + *v:* Vertical open + *gv:* Vertical open silently + +======================================== From 4cee6b3f9d49a2f67bd3017114356ec95161c150 Mon Sep 17 00:00:00 2001 From: Kassio Borges Date: Wed, 16 Apr 2014 14:32:53 -0300 Subject: [PATCH 30/30] add documentation about g:ack_default_options --- doc/ack.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/ack.txt b/doc/ack.txt index ff27e726..33c10529 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -76,15 +76,26 @@ CONFIGURATION *ack-configuration* *g:ackprg* g:ackprg -Default for ubuntu: "ack-grep -s -H --nocolor --nogroup --column" -Default for other systems: "ack -s -H --nocolor --nogroup --column" +Default for ubuntu: "ack-grep" +Default for other systems: "ack" Use this option to specify the ack command and its options +Example: +> + let g:ackprg = "other-bin-ack" +< + + g:ack_default_options* +g:ack_default_options +Default: " -s -H --nocolor --nogroup --column" + +Use this option to specify the options used by ack + Example: > let g:ackprg = - \ "ack -H --nocolor --nogroup --column --smart-case --follow" + \ " -s -H --nocolor --nogroup --column --smart-case --follow" < *g:ack_apply_qmappings*