SearchPosition : Show relation to search pattern matches in range or buffer.
| script karma |
Rating 3/3,
Downloaded by 607
|
Comments, bugs, improvements
|
Vim wiki
|
| created by |
| Ingo Karkat |
| |
| script type |
| utility |
| |
| description |
DESCRIPTION
The mappings, command and operator provided by this plugin search a range or
the entire buffer for a pattern (defaulting to the current 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 for /\<SearchPosition\>/
5 matches in this fold, 9 before, 6 following; total 21 for /endif/
On sole match in this line, 40 in following lines 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 current 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 current search pattern (@/) if {pattern} is
omitted). 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.
<Leader><A-n>{motion} Show position for the current search pattern in the
lines covered by {motion}.
[count]<A-n> Show position for the current search pattern in the
entire buffer, or [count] following lines.
{Visual}<A-n> Show position for the current search pattern in the
selected lines.
[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. |
| |
| install details |
INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vba.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 SearchPosition.vba.gz
:so %
To uninstall, use the :RmVimball command.
DEPENDENCIES
- Requires Vim 7.0 or higher.
CONFIGURATION
If you want to use different mappings, map your keys to the
<Plug>SearchPosition* mapping targets _before_ sourcing this script (e.g. in
your .vimrc):
nmap <silent> <Leader>,n <Plug>SearchPositionOperator
nmap <silent> <Leader>n <Plug>SearchPositionCurrent
vmap <silent> <Leader>n <Plug>SearchPositionCurrent
nmap <silent> <Leader>m <Plug>SearchPositionWholeCword
vmap <silent> <Leader>m <Plug>SearchPositionCword
The highlight group for the report message can be set via
let g:SearchPosition_HighlightGroup = 'ModeMsg'
To shorten the report message, the [range] and used search pattern can be
omitted from the message; by default, both are included in the message text:
let g:SearchPosition_ShowRange = 1
let g:SearchPosition_ShowPattern = 1 |
| |
script versions (upload new version)
Click on the package to download.
| SearchPosition.vba.gz |
1.13 |
2010-10-08 |
7.0 |
Ingo Karkat |
- BUG: The previous fix for the incorrect reporting of sole match in folded line was susceptible to non-local matches when current line is the first line. |
| SearchPosition.vba.gz |
1.12 |
2010-10-08 |
7.0 |
Ingo Karkat |
- BUG: Visual mode <A-m> /Plug>SearchPositionCword mapping on multi-line selection searched for ^@, not the newline character \n.
- BUG: Incorrect reporting of sole match in folded line when the current line is empty and the pattern starts matching a newline character.
- Using SearchPosition#SavePosition() instead ofVim version-dependent) mark to keep the cursor at the position where the operator was invokedonly necessary with a backward {motion}). |
| SearchPosition.vba.gz |
1.11 |
2010-06-02 |
7.0 |
Ingo Karkat |
Appended "; total N" to evaluations that excluded the match on the cursor from the "overall" count, as it was misleading what "overall" meant in this context. |
| SearchPosition.vba.gz |
1.10 |
2010-01-08 |
7.0 |
Ingo Karkat |
- Moved functions from plugin to separate autoload script.
- BUG: Wrong reporting of additional occurrences when the current line is outside the passed range.
- BUG: Catch non-existing items in evaluations that can be caused by e.g having \%# inside the search pattern. Warn about "special atoms have distorted the tally" in such cases. |
| SearchPosition.vba.gz |
1.03 |
2010-01-05 |
7.0 |
Ingo Karkat |
ENH: Offering a whole-word ALT-M mapping in addition to the former literal search (which is now mapped to g_ALT-M), like the |star| and |gstar| commands. |
| SearchPosition.vba.gz |
1.02 |
2009-09-11 |
7.0 |
Ingo Karkat |
BUG: Cannot set mark " in Vim 7.0 and 7.1; using mark z instead. This only affected the <Leader><A-n>{motion} command. |
| SearchPosition.vba.gz |
1.01 |
2009-06-19 |
7.0 |
Ingo Karkat |
The jumplist is not clobbered anymore by the :SearchPosition command. |
| SearchPosition.vba.gz |
1.00 |
2009-05-15 |
7.0 |
Ingo Karkat |
Initial upload |
ip used for rating: 54.224.75.101
|