vim-searchhi


Ⅰ. 插件描述

Highlight the current search result differently

Ⅱ. 基本信息

创建日期:  2019-02-10
使用用户:  5
Github星:  28
插件作者:  qxxxb

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'qxxxb/vim-searchhi'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'qxxxb/vim-searchhi'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'qxxxb/vim-searchhi'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/qxxxb/vim-searchhi

Ⅳ. 文档说明

# vim-searchhi

Highlight the current search result in a different style than the other search
results.

Demo gif

Credits

This plugin would not have existed without [vim-searchant]. It uses the same
basic implementation for highlighting the current search result.

Features

  • Smooth integration with standard search as well as other search-enhancing
    plugins (e.g. [vim-anzu], [vim-asterisk]).
  • Uses a custom highlight group for the cursor when it's inside a search result.
  • Behaves appropriately in Visual mode.
  • Highlighting is updated predictably when the cursor is moved, as well as
    when switching buffers and windows. It can also be toggled with custom

autocommands.

  • User autocommands are provided and executed when highlighting is turned on
    and off.

Note: This plugin uses a lot of <Plug> mappings. An alternative plugin is
[vim-searchlight], which has the same basic functionality but doesn't require
any mappings.

Quick start

nmap n <Plug>(searchhi-n)
nmap N <Plug>(searchhi-N)
nmap * <Plug>(searchhi-*)
nmap g* <Plug>(searchhi-g*)
nmap # <Plug>(searchhi-#)
nmap g# <Plug>(searchhi-g#)
nmap gd <Plug>(searchhi-gd)
nmap gD <Plug>(searchhi-gD)

vmap n <Plug>(searchhi-v-n)
vmap N <Plug>(searchhi-v-N)
vmap * <Plug>(searchhi-v-*)
vmap g* <Plug>(searchhi-v-g*)
vmap # <Plug>(searchhi-v-#)
vmap g# <Plug>(searchhi-v-g#)
vmap gd <Plug>(searchhi-v-gd)
vmap gD <Plug>(searchhi-v-gD)

nmap <silent> <C-L> <Plug>(searchhi-clear-all)
vmap <silent> <C-L> <Plug>(searchhi-v-clear-all)

Integration with [vim-anzu]:

let g:searchhi_user_autocmds_enabled = 1
let g:searchhi_redraw_before_on = 1

augroup searchhi
    autocmd!
    autocmd User SearchHiOn AnzuUpdateSearchStatusOutput
    autocmd User SearchHiOff echo g:anzu_no_match_word
augroup END

Example with [vim-asterisk]:

map * <Plug>(asterisk-*)<Plug>(searchhi-update)
map # <Plug>(asterisk-#)<Plug>(searchhi-update)
map g* <Plug>(asterisk-g*)<Plug>(searchhi-update)
map g# <Plug>(asterisk-g#)<Plug>(searchhi-update)

map z* <Plug>(asterisk-z*)<Plug>(searchhi-update)
map z# <Plug>(asterisk-z#)<Plug>(searchhi-update)
map gz* <Plug>(asterisk-gz*)<Plug>(searchhi-update)
map gz# <Plug>(asterisk-gz#)<Plug>(searchhi-update)

Customization

Highlight style

The current search result is highlighted with CurrentSearch, and the cursor
when it's inside a search result is highlighted with SearchCursor. Example:

highlight CurrentSearch
    \ cterm=reverse,bold ctermfg=108 ctermbg=235
    \ gui=reverse,bold guifg=#8ec07c guibg=#282828

highlight link SearchCursor WarningMsg

By default, CurrentSearch is linked to Incsearch, which works nicely if your
Incsearch and Search highlight groups are visually distinguishable.
SearchCursor is linked to Normal by default.

Autocommands

The autocommands SearchHiOn and SearchHiOff are executed when highlighting
is turned on or off. Below is an example that blinks the cursor when search
highlighting is turned on, making the cursor easier to find. [vim-anzu] is also
used to echo the search count.

let g:searchhi_user_autocmds_enabled = 1
let g:searchhi_redraw_before_on = 1

augroup searchhi
    autocmd!

    autocmd User SearchHiOn
        \ set guicursor=
            \c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,
            \n-v:block-blinkwait20-blinkon20-blinkoff20 |
        \ AnzuUpdateSearchStatusOutput

    autocmd User SearchHiOff set guicursor& | echo g:anzu_no_match_word
augroup END

Autocommands for toggling search highlighting

Highlighting for all search results can be toggled with custom autocommands.
Example:

let g:searchhi_clear_all_autocmds = 'InsertEnter'
let g:searchhi_update_all_autocmds = 'InsertLeave'

Note: Using CursorMoved for these will cause issues. If you want search
highlighting to be cleared as soon as the cursor moves, use this:

let g:searchhi_clear_all_asap = 1

Because g:searchhi_clear_all_asap and g:searchhi_clear_all_autocmds both
use a hack that directly sets nohlsearch, you may also need to use the
following maps to make sure that incsearch works properly when searching:

nmap / <Plug>(searchhi-/)
nmap ? <Plug>(searchhi-?)

vmap / <Plug>(searchhi-v-/)
vmap ? <Plug>(searchhi-v-?)

添加新评论