Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ Controls whether the match's line is vertically centered within the window when
let g:LoupeCenterResults=0
```

<p align="right"><a name="gloupehlsearchtimeout" href="#user-content-gloupehlsearchtimeout"><code>g:LoupeHlSearchTimeout</code></a></p>
### `g:LoupeHlSearchTimeout` (number, default: 0)<a name="loupe-gloupehlsearchtimeout-number-default-0" href="#user-content-loupe-gloupehlsearchtimeout-number-default-0"></a>

" In milliseconds.
" To enable this feature, set to a number > 0:

Controls how long (in milliseconds) hlsearch remains active after a search (<strong>`/`</strong>, <strong>`?`</strong>) is executed or a jump (<strong>`n`</strong>, <strong>`*`</strong> etc.) is performed. By default, there is no timeout. Setting this option to a positive number will enable the timeout if timers are supported (i.e. <strong>`has('timers')`</strong>).

```
let g:LoupeHlSearchTimeout=1000
```

## Functions<a name="loupe-functions" href="#user-content-loupe-functions"></a>

<p align="right"><a name="loupehlmatch" href="#user-content-loupehlmatch"><code>loupe#hlmatch()</code></a></p>
Expand Down
26 changes: 26 additions & 0 deletions autoload/loupe.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,29 @@ function! loupe#hlmatch() abort
let w:loupe_hlmatch=matchadd(l:highlight, l:pattern)
endif
endfunction

""
" @function loupe#hlsearch
"
" Make hlsearch transient.
"
function! loupe#hlsearch() abort
""
" @option g:LoupeHlSearchTimeout number 0
" How long after a search command before hlsearch is deactivated.
" In milliseconds.
" To enable this feature, set to a number > 0:
"
" ```
" let g:LoupeHlSearchTimeout=1000
" ```
let l:time=get(g:, 'LoupeHlSearchTimeout', 0)

if l:time > 0 && has('timers')
" activate hlsearch
set hlsearch

" schedule hlsearch deactivation
let g:hlsearch_timer=timer_start(l:time, 'loupe#private#clear_hlsearch')
endif
endfunction
11 changes: 10 additions & 1 deletion autoload/loupe/private.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function! loupe#private#prepare_highlight(result) abort
if has('autocmd')
augroup LoupeHightlightMatch
autocmd!
autocmd CursorMoved * :call loupe#hlmatch()
autocmd CursorMoved * :call loupe#hlmatch() | :call loupe#hlsearch()
augroup END
endif
return a:result
Expand All @@ -89,6 +89,15 @@ function! loupe#private#clear_highlight() abort
endif
endfunction

" Deactivate hlsearch once the configured timeout has passed since the most
" recent search command.
function! loupe#private#clear_hlsearch(timer) abort
" only process the most recent timer
if a:timer == g:hlsearch_timer
set nohlsearch
endif
endfunction

" Called from WinEnter autocmd to clean up stray `matchadd()` vestiges.
" If we switch into a window and there is no 'hlsearch' in effect but we do have
" a `w:loupe_hlmatch` variable, it means that `:nohighight` was probably run
Expand Down
11 changes: 11 additions & 0 deletions doc/loupe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ when jumping (via |n|, |N| etc). To disable, set to 0:
>
let g:LoupeCenterResults=0
<

*g:LoupeHlSearchTimeout*
|g:LoupeHlSearchTimeout| number (default: 0)

Controls how long (in milliseconds) hlsearch remains active after a search
(|/|, |?|) is executed or a jump (|n|, |star| etc.) is performed. By default,
there is no timeout. Setting this option to a positive number will enable the
timeout if timers are supported.
>
let g:LoupeHlSearchTimeout=1000
<
FUNCTIONS *loupe-functions*

loupe#hlmatch() *loupe#hlmatch()*
Expand Down
3 changes: 2 additions & 1 deletion plugin/loupe.vim
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ function! s:map(keys, name)
\ a:keys .
\ 'zv' .
\ s:center_string .
\ ':call loupe#hlmatch()<CR>'
\ ':call loupe#hlmatch()<CR>' .
\ ':call loupe#hlsearch()<CR>'
endfunction

""
Expand Down