SearchHighlighting : Highlighting of searches via star, auto-highlighting.
| script karma |
Rating 5/2,
Downloaded by 78
|
Comments, bugs, improvements
|
Vim wiki
|
| created by |
| Ingo Karkat |
| |
| script type |
| utility |
| |
| description |
DESCRIPTION
This plugin changes the star command *, so that it doesn't jump to the next
match. (Unless you supply a [count], so 1* now restores the old * behavior.)
If you issue a star command on the same text as before, the search
highlighting is turned off (via :nohlsearch); the search pattern remains
set, so a n / N command will turn highlighting on again. With this, you
can easily toggle highlighting for the current word / visual selection.
With the disabling of the jump to the next match, there is no difference
between * and # any more, so the # key can now be used for some other mapping.
This plugin also extends the star command to visual mode, where instead of
the current word, the selected text is used as the literal search pattern.
The auto-search functionality instantly highlights the word under the cursor
when typing or moving around. This can be helpful while browsing source code;
whenever you position the cursor on an identifier, all other occurrences are
instantly highlighted. This functionality is toggled on/off via <Leader>*. You
can also :nohlsearch to temporarily disable the highlighting.
SEE ALSO
- mark.vim (vimscript #2666) can highlight several patterns in different
colors simultaneously.
- SearchAlternatives.vim (vimscript #4146) can add and subtract search
alternatives via mappings and commands.
RELATED WORKS
I came up with this on my own; however, the idea can be traced back to
francoissteinmetz and da.thompson in the comments of vimtip #1 (now at
http://vim.wikia.com/wiki/VimTip1): >
map <silent> <F10> :set invhls<CR>:let @/="<C-r><C-w>"<CR>
- highlight_word_under_cursor.vim (vimscript #4287) implements the search
auto-highlighting of the whole and optionally current word.
- HiCursorWords (vimscript #4306) highlights the word under the cursor, with
optional delay and limited to certain syntax groups.
- star search (vimscript #4335) changes the behavior of * to not jump to the
next match, and includes the visual search from the next plugin
- https://github.com/bronson/vim-visual-star-search can do searching of the
visual selection
USAGE
* Toggle search highlighting for the current whole
\<word\> on/off.
g* Toggle search highlighting for the current word
on/off.
{Visual}* Toggle search highlighting for the selection on/off.
[count]* Search forward for the [count]'th occurrence of the
[count]g* word nearest to the cursor.
{Visual}[count]*
<Leader>* Toggle auto-search highlighting (using the last
{what}; default is "wword").
:SearchAutoHighlighting [{what}]
Turn on automatic highlighting of occurrences of
{what} in normal mode, and the selected text in visual
/ select mode. Possible values:
wword: whole cword, like star; this is the default
wWORD: whole cWORD, delimited by whitespace
cword: current word under cursor
cWORD: current WORD under cursor
line: current text in line, excluding indent and
trailing whitespace
exactline: exact current line
:NoSearchAutoHighlighting
Turn off automatic highlighting. |
| |
| 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 SearchHighlighting*.vmb.gz
:so %
To uninstall, use the :RmVimball command.
DEPENDENCIES
- Requires Vim 7.0 or higher.
CONFIGURATION
If you do not want the new non-jumping behavior of the star commands at all:
let g:SearchHighlighting_NoJump = 0
let g:SearchHighlighting_ExtendStandardCommands = 1
If you want the new non-jumping behavior, but map it to different keys:
let g:SearchHighlighting_ExtendStandardCommands = 1
nmap <Leader>* <Plug>SearchHighlightingStar
nmap <Leader>g* <Plug>SearchHighlightingGStar
vmap <Leader>* <Plug>SearchHighlightingStar
If you want a mapping to turn off hlsearch, use this:
nmap <A-/> <Plug>SearchHighlightingNohlsearch
vmap <A-/> <Plug>SearchHighlightingNohlsearch
To toggle hlsearch (temporarily, so that a new search or n command will
automatically re-enable it), use:
nmap <F12> <Plug>SearchHighlightingToggleHlsearch
vmap <F12> <Plug>SearchHighlightingToggleHlsearch |
| |
script versions (upload new version)
Click on the package to download.
ip used for rating: 107.20.129.212
|