Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abb87ab
Showing
7 changed files
with
1,373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4191 | ||
|
||
DESCRIPTION | ||
This plugin defines a command and mappings to quickly list all occurrences of | ||
the current search pattern, passed pattern, current word or selection in the | ||
quickfix list. This is useful to get a somewhat persistent list of matches | ||
that act like bookmarks, so you can recall them later (when your search | ||
pattern has changed). | ||
|
||
HOW IT WORKS | ||
The plugin uses :vimgrep over the current buffer. | ||
|
||
SOURCE | ||
Inspired by vimtip #483: Using GREP for a "list occurrences" and quickfix help | ||
command. | ||
http://vim.wikia.com/wiki/Search_using_quickfix_to_list_occurrences | ||
command GREP :execute 'grep '.expand('<cword>') expand('%') | :copen | cc | ||
|
||
SEE ALSO | ||
- The GrepCommands plugin (vimscript #4173) provides additional grep commands | ||
covering arguments, buffers, windows and tab pages. | ||
- The FindOccurrence plugin (vimscript #0000) can also show all occurrences of | ||
the <cword>, current search results, etc., but instead of the quickfix list, | ||
the result is either jumped to or listed. | ||
- The SearchPosition plugin (vimscript #2634) shows the relation of the cursor | ||
position to the other matches of the search pattern, and provides similar | ||
mappings. Like the quickfix list, it can provide an orientation of where and | ||
how many matches there are. | ||
|
||
RELATED WORKS | ||
- outline (vimscript #1947) creates a custom view of the file based on regex, | ||
in a scratch buffer | ||
- ttoc (vimscript #2014) is based on outline and creates a regexp-based table | ||
of contents of the current buffer | ||
|
||
USAGE | ||
:GrepHere [{pattern}] | ||
:GrepHere /{pattern}/[g][j] | ||
:GrepHereAdd [{pattern}] | ||
:GrepHereAdd /{pattern}/[g][j] | ||
Grep the passed pattern (or current search pattern if | ||
omitted) in the current file (or the current entry of | ||
the quickfix list). | ||
|
||
<A-N> Grep the current search pattern in the current file | ||
and show matching lines in the quickfix window (but | ||
don't go there). | ||
This is similar to [N defined by | ||
FindOccurrence.vim, but uses the quickfix list | ||
instead of just printing all matching lines. | ||
|
||
<A-M> Grep the current whole word under the cursor in the | ||
current file and show matching lines in the quickfix | ||
window (but don't go there). | ||
This is similar to [I defined by | ||
FindOccurrence.vim, but uses the quickfix list | ||
instead of just printing all matching lines. | ||
g<A-M> Grep the current word under the cursor in the current | ||
file and show matching lines in the quickfix window | ||
(but don't go there). | ||
Only whole keywords are searched for, like with the | ||
star command. | ||
{Visual}<A-M> Grep the selected text in the current file and show | ||
matching lines in the quickfix window (but don't go | ||
there). | ||
|
||
Imagine 'M' stood for "more occurrences". | ||
These mappings reuse the last used <cword> when issued | ||
on a blank line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
" GrepHere.vim: List occurrences in the current buffer in the quickfix window. | ||
" | ||
" DEPENDENCIES: | ||
" - GrepCommands.vim autoload script | ||
" - ingosearch.vim autoload script | ||
" - ingowindow.vim autoload script | ||
" | ||
" Copyright: (C) 2003-2012 Ingo Karkat | ||
" The VIM LICENSE applies to this script; see ':help copyright'. | ||
|
||
" Maintainer: Ingo Karkat <ingo@karkat.de> | ||
" | ||
" REVISION DATE REMARKS | ||
" 1.00.002 24-Aug-2012 Add mappings for the [whole] <cword> via | ||
" GrepHere#SetCword(), analog to the | ||
" SearchPosition plugin's implementation. | ||
" Factor out the mapping logic to GrepHere#List(). | ||
" Extract g:GrepHere_MappingGrepFlags. | ||
" 001 21-Mar-2012 file creation from plugin script | ||
|
||
function! GrepHere#Grep( count, grepCommand, pattern, ... ) | ||
let l:currentFile = expand('%') | ||
|
||
if empty(l:currentFile) && ingowindow#IsQuickfixList() | ||
" Use the file from the current line in the quickfix window. | ||
let l:currentFile = ingowindow#ParseFileFromQuickfixList() | ||
if empty(l:currentFile) && ingowindow#GotoPreviousWindow() | ||
" If the cursor is on no file name line in the quickfix window, use | ||
" the previous window instead. | ||
let l:currentFile = expand('%:p') | ||
noautocmd wincmd p | ||
endif | ||
endif | ||
|
||
if empty(l:currentFile) | ||
echohl ErrorMsg | ||
echomsg 'E32: No file name' | ||
echohl None | ||
return 0 | ||
endif | ||
|
||
return call('GrepCommands#Grep', [a:count, a:grepCommand, [l:currentFile], a:pattern] + a:000) | ||
endfunction | ||
|
||
let s:pattern = '' | ||
function! GrepHere#SetCword( isWholeWord ) | ||
let l:cword = expand('<cword>') | ||
if ! empty(l:cword) | ||
let s:pattern = ingosearch#LiteralTextToSearchPattern(l:cword, a:isWholeWord, '') | ||
endif | ||
return s:pattern | ||
endfunction | ||
|
||
function! GrepHere#List( pattern ) | ||
if GrepHere#Grep(0, 'vimgrep', a:pattern, g:GrepHere_MappingGrepFlags) | ||
copen | ||
call ingowindow#GotoPreviousWindow() | ||
endif | ||
endfunction | ||
|
||
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax : |
Oops, something went wrong.