# That one:
# * uses autoload for lazy loading
# * is ported to vim9script for code simplification and performance
-# * uses lists, instead of pack of variables for keeping the state
+# * uses lists, instead of pack of variables to keep the state
# * does not pollute global variable namespace
-# * has removed old Vim versions support, expecting for modern functions
# * has ability only to highlight the current word
hi MarkWord1 ctermfg=Black ctermbg=Cyan
hi MarkWord5 ctermfg=Black ctermbg=Magenta
hi MarkWord6 ctermfg=Black ctermbg=Blue
-const Offset = 3333
-var Show = false
+const MarkIdOffset = 3333
+var Show: bool
var Words: list<string>
-var Idx = 1
+var Idx: number
def Init()
if len(Words) > 0 | return | endif
Words = repeat([""], i - 1)
enddef
-def Del(i: number)
- Words[i] = ""
- silent! matchdelete(Offset + i + 1)
-enddef
-
-def Add(i: number, word: string)
- Words[i] = word
- matchadd("MarkWord" .. (i + 1), word, -10, Offset + i + 1)
+def WinRefresh()
+ for i in range(len(Words))
+ exec "syntax clear MarkWord" .. (i + 1)
+ silent! matchdelete(MarkIdOffset + i + 1)
+ if (Words[i] == "") || !Show | continue | endif
+ matchadd("MarkWord" .. (i + 1), Words[i], -10, MarkIdOffset + i + 1)
+ endfor
enddef
export def Refresh()
Init()
- var word: string
- for i in range(len(Words))
- exec "syntax clear MarkWord" .. (i + 1)
- if Words[i] == "" | continue | endif
- silent! matchdelete(Offset + i + 1)
- if Show | Add(i, Words[i]) | endif
- endfor
+ var nr = winnr()
+ windo WinRefresh()
+ exec ":" .. nr .. "wincmd w"
enddef
export def Toggle()
enddef
def Do(word: string)
- Init()
for i in range(len(Words))
- if !Show | Del(i)
- elseif Words[i] == word | Del(i) | return
+ if !Show | Words[i] = ""
+ elseif Words[i] == word | Words[i] = "" | return
endif
endfor
if !Show | Show = true | endif
for i in range(len(Words))
if Words[i] != "" | continue | endif
- Add(i, word)
- Idx = ((i + 1) == len(Words)) ? 1 : (i + 1)
+ Words[i] = word
+ Idx = ((i + 1) == len(Words)) ? 0 : (i + 1)
return
endfor
- Del(Idx)
- Add(Idx, word)
- Idx = ((Idx + 1) == len(Words)) ? 1 : (Idx + 1)
+ Words[Idx] = word
+ Idx = ((Idx + 1) == len(Words)) ? 0 : (Idx + 1)
enddef
export def Word()
+ Init()
Do('\<' .. expand("<cword>") .. '\>')
+ Refresh()
enddef