sponsor Vim development Vim logo Vim Book Ad

GrepHere : List occurrences in the current buffer in the quickfix window.

 script karma  Rating 2/2, Downloaded by 307    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
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.
 
install details
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim GrepHere*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the GrepCommands.vim plugin (vimscript #4173).

CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

The :GrepHere command without arguments lists all occurrences, and (other
than the ALT-SHIFT-N mapping), jumps to the first occurrence. You can change
that via:
    let g:GrepHere_EmptyCommandGrepFlags = 'g'
When you provide any arguments to :GrepHere, provide the flags there, if
desired.

By default, the mappings list all occurrences in a line and do not jump to the
first match; you can adapt the behavior by removing some of the :vimgrep
flags:
    let g:GrepHere_MappingGrepFlags = 'gj'

If you want to use different mappings, map your keys to the
<Plug>(GrepHere...) mapping targets _before_ sourcing the script (e.g. in your
vimrc):
    nmap <Leader>N <Plug>(GrepHereCurrent)
    nmap <Leader>M <Plug>(GrepHereWholeCword)
    nmap <Leader>gM <Plug>(GrepHereCword)
    vmap <Leader>M <Plug>(GrepHereCword)
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
GrepHere-1.10.vmb.gz 1.10 2012-09-06 7.0 Ingo Karkat Make default flags for an empty :GrepHere command configurable via g:GrepHere_EmptyCommandGrepFlags. Default to 'g': List all occurrences, jump to first occurrence.
GrepHere-1.00.vmb.gz 1.00 2012-08-24 7.0 Ingo Karkat Initial upload
ip used for rating: 54.87.136.181

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo