]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(hlyamk): Allow to highlight put regions using TextPutPost
authorFoxe Chen <chen.foxe@gmail.com>
Mon, 11 May 2026 17:19:19 +0000 (17:19 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 11 May 2026 17:23:01 +0000 (17:23 +0000)
closes: #20196

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/usr_05.txt
runtime/doc/version9.txt
runtime/pack/dist/opt/hlyank/plugin/hlyank.vim

index 56e7fb9e7847e9bd2e9306232e5cb84e326b5d1e..4a3444b61ae43f5d9a51be6561fee75ded3936e1 100644 (file)
@@ -1,4 +1,4 @@
-*usr_05.txt*   For Vim version 9.2.  Last change: 2026 Feb 14
+*usr_05.txt*   For Vim version 9.2.  Last change: 2026 May 11
 
 
                     VIM USER MANUAL    by Bram Moolenaar
@@ -509,6 +509,16 @@ To highlight in visual mode, use: >
 To disable the effect of the plugin after it has been loaded: >
        au! hlyank
 
+Additionally, the plugin can also highlight regions that are put using the
+|TextPutPost| autocommand.  This is by default disabled and can be enabled
+using: >
+       :let g:hlput_enable = v:true
+<
+The following configuration variables can be used are "g:hlput_hlgroup" and
+"g:hlput_duration", which have the same effect as their yank counterparts: >
+       :let g:hlput_hlgroup = 'IncSearch'
+       :let g:hlput_duration = 300
+
 ------------------------------------------------------------------------------
 Adding the osc52 package               *osc52-install* *package-osc52*
 ------------------------------------------------------------------------------
index 45a25b08bb900e2b7545b4fa9278667d1a508d72..5121fe90c6f4faf982d8b274eb3c0032ce7bd63d 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.2.  Last change: 2026 May 10
+*version9.txt* For Vim version 9.2.  Last change: 2026 May 11
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -52627,6 +52627,8 @@ Other ~
 - |:command-completion-customlist| can return a list of dictionaries with
   kind/menu/info/abbr for the popup menu.
 - |C-indenting| detects comments better.
+- The |package-hlyank| can now optionally highlight the last put region as
+  well.
 
 Platform specific ~
 -----------------
index 3e0cdb9bfb1e1c510c862e8517bcf37044cc142a..27e2a032ed8866a03e01076ac8c5e7627502a5ef 100644 (file)
@@ -1,7 +1,7 @@
 vim9script
 
 # Highlight Yank plugin
-# Last Change: 2026 Apr 11
+# Last Change: 2026 May 11
 
 def HighlightedYank()
 
@@ -36,8 +36,34 @@ def HighlightedYank()
   endif
 enddef
 
+export def HighlightedPut()
+    if !get(g:, "hlput_enable", false)
+      return
+    endif
+
+    var hlgroup = get(g:, "hlput_hlgroup", "IncSearch")
+    var duration = min([get(g:, "hlput_duration", 300), 3000])
+
+    var [beg, end] = [getpos("'["), getpos("']")]
+    var type = v:event.regtype ?? 'v'
+    var pos = getregionpos(beg, end, {type: type, exclusive: false})
+
+    var m = matchaddpos(hlgroup, pos->mapnew((_, v) => {
+        var col_beg = v[0][2] + v[0][3]
+        var col_end = v[1][2] + v[1][3] + 1
+        return [v[0][1], col_beg, col_end - col_beg]
+    }))
+    var winid = win_getid()
+    timer_start(duration, (_) => {
+        if winbufnr(winid) != -1
+            m->matchdelete(winid)
+        endif
+    })
+enddef
+
 augroup hlyank
   autocmd!
   autocmd TextYankPost * HighlightedYank()
+  autocmd TextPutPost * HighlightedPut()
 augroup END
 # vim:sts=2:sw=2:et: