Skip to content

vim-scripts/SearchPosition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This is a mirror of http://www.vim.org/scripts/script.php?script_id=2634

DESCRIPTION
The mappings, command and operator provided by this plugin search a range or
the entire buffer for a pattern (defaulting to the last search pattern),
and print a summary of the number of occurrences above, below and on the
current line, e.g.:
    1 match after cursor in this line, 8 following, 2 in previous lines;
        total 10 within 11,42 for /\<SearchPosition\>/

    5 matches in this fold, 9 before, 6 following; total 21 spanning the
    entire buffer for /endif/

    On sole match in this line, 40 in following lines within 24,171 for /let/

    :144,172 7 matches in this fold for /let/

This provides better orientation in a buffer without having to first jump from
search result to search result.

MOTIVATION
In its simplest implementation
    :nnoremap <A-n> :%s///gn<CR>
   41 matches on 17 lines
prints the number of matches for the last search pattern. This plugin
builds on top of this by providing more context with regards to the current
cursor position plus additional information.

This plugin is similar to IndexedSearch.vim (vimscript #1682) by Yakov Lerner.

USAGE
:[range]SearchPosition [/][{pattern}][/]
                        Show position of the search results for {pattern} (or
                        the last search pattern (quote/) if {pattern} is
                        omitted). Without [/], only literal whole words are
                        matched. :search-args
                        All lines in [range] (or the entire buffer
                        if omitted) are considered, and the number of matches
                        in relation to the current cursor position is echoed
                        to the command line.

:[range]SearchPositionMultiple /{pattern1}/,/{pattern2}/[,...]
:[range]SearchPositionMultiple {word1},{word2}[,...]
                        Show positions and tallies of the search results for
                        {pattern1}, {pattern2}, ... Without [/] delimiters,
                        only literal whole {word1}, {word2}, ... are matched.
                        :search-args Useful to compare the number of
                        occurrences for multiple variants.

<Leader><A-n>{motion}   Show position for the last search pattern in the
                        lines covered by {motion}.
[count]<A-n>            Show position for the last search pattern in the
                        entire buffer, or [count] following lines.
{Visual}<A-n>           Show position for the last search pattern in the
                        selected lines.

                        The default mapping <A-n> was chosen because one often
                        invokes this when jumping to matches via n/N, so <A-n>
                        is easy to reach. Imagine 'n' stood for "next
                        searches".

[count]<A-m>            Show position for the whole word under the cursor in
                        the entire buffer, or [count] following lines.
                        Only whole keywords are searched for, like with the
                        star command.
[count]g<A-m>           Show position for the word under the cursor in the
                        entire buffer, or [count] following lines.
                        Also finds contained matches, like gstar.

{Visual}<A-m>           Show position for the selected text in the entire
                        buffer.

                        Imagine 'm' stood for "more occurrences".
                        These mappings reuse the last used <cword> when issued
                        on a blank line.

About

Show relation to search pattern matches in range or buffer.

Resources

Stars

Watchers

Forks

Packages

No packages published