Skip to content

Commit 8b31ee4

Browse files
committed
.
1 parent 9d534c6 commit 8b31ee4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

plugin/hlyanked.vim

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if !exists('g:hlyanked_hlgroup')
1919
endif
2020

2121
if !exists('g:hlyanked_timeout')
22-
g:hlyanked_timeout = 2000
22+
g:hlyanked_timeout = 400
2323
endif
2424

2525
# ----------------------------------------------------
@@ -29,12 +29,8 @@ var timer_id = -1
2929
var match_id = -1
3030

3131
def HighlightYanked()
32-
# Remove existing timers.
33-
# In practice this is never needed, but still...
34-
if timer_id != -1
35-
timer_stop(timer_id)
36-
timer_id = -1
37-
endif
32+
# Remove leftover timers and highlights
33+
KillHighlight()
3834

3935
# Get extremes of yanking: start = (l0, c0), end = (l1, c1)
4036
var l0 = line("'[")
@@ -58,8 +54,22 @@ def HighlightYanked()
5854
enddef
5955

6056
def RemoveHighlight(timer: number)
61-
matchdelete(match_id)
62-
match_id = -1
57+
if match_id != -1
58+
matchdelete(match_id)
59+
match_id = -1
60+
endif
61+
enddef
62+
63+
def StopTimer(timer: number)
64+
if timer_id != -1
65+
timer_stop(timer_id)
66+
timer_id = -1
67+
endif
68+
enddef
69+
70+
def KillHighlight()
71+
StopTimer(timer_id)
72+
RemoveHighlight(match_id)
6373
enddef
6474

6575
augroup HighlightYanked
@@ -71,9 +81,5 @@ augroup END
7181

7282
augroup KillHighlight
7383
autocmd!
74-
autocmd WinLeave * if timer_id != -1
75-
| timer_stop(timer_id)
76-
| timer_id = -1
77-
| RemoveHighlight(0)
78-
| endif
84+
autocmd WinLeave * KillHighlight()
7985
augroup END

0 commit comments

Comments
 (0)