diff options
author | Christian Clason <christian.clason@uni-due.de> | 2020-07-06 03:30:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-05 21:30:12 -0400 |
commit | 4ab7bbf3eaeacc32e8970b76a19c8682f98cc183 (patch) | |
tree | 602389793048292552211ac1f8f3f0281c345a8a /runtime/lua/vim/highlight.lua | |
parent | f9579d473e00c11c0b76ef5fe0934ef6ec13ed34 (diff) | |
download | rneovim-4ab7bbf3eaeacc32e8970b76a19c8682f98cc183.tar.gz rneovim-4ab7bbf3eaeacc32e8970b76a19c8682f98cc183.tar.bz2 rneovim-4ab7bbf3eaeacc32e8970b76a19c8682f98cc183.zip |
lua: add options to highlight.on_yank (#12549)
NOTE: Configuration options have changed for highlight.on_yank.
Check help for |:help highlight.on_yank()|
Diffstat (limited to 'runtime/lua/vim/highlight.lua')
-rw-r--r-- | runtime/lua/vim/highlight.lua | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 69c3c8a4dc..ce0a3de520 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -23,24 +23,41 @@ function highlight.range(bufnr, ns, higroup, start, finish, rtype, inclusive) end +local yank_ns = api.nvim_create_namespace('hlyank') --- Highlight the yanked region --- --- use from init.vim via ---- au TextYankPost * lua require'vim.highlight'.on_yank() +--- au TextYankPost * lua vim.highlight.on_yank() --- customize highlight group and timeout via ---- au TextYankPost * lua require'vim.highlight'.on_yank("IncSearch", 500) +--- au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=150} +--- customize conditions (here: do not highlight a visual selection) via +--- au TextYankPost * lua vim.highlight.on_yank {on_visual=false} --- --- @param higroup highlight group for yanked region --- @param timeout time in ms before highlight is cleared --- @param event event structure -function highlight.on_yank(higroup, timeout, event) - event = event or vim.v.event +-- @param opts dictionary with options controlling the highlight: +-- - higroup highlight group for yanked region (default "IncSearch") +-- - timeout time in ms before highlight is cleared (default 150) +-- - on_macro highlight when executing macro (default false) +-- - on_visual highlight when yanking visual selection (default true) +-- - event event structure (default vim.v.event) +function highlight.on_yank(opts) + vim.validate { + opts = { opts, + function(t) if t == nil then return true else return type(t) == 'table' end end, + 'a table or nil to configure options (see `:h highlight.on_yank`)', + }} + opts = opts or {} + local event = opts.event or vim.v.event + local on_macro = opts.on_macro or false + local on_visual = (opts.on_visual ~= false) + + if (not on_macro) and vim.fn.reg_executing() ~= '' then return end if event.operator ~= 'y' or event.regtype == '' then return end - higroup = higroup or "IncSearch" - timeout = timeout or 500 + if (not on_visual) and event.visual then return end + + local higroup = opts.higroup or "IncSearch" + local timeout = opts.timeout or 150 local bufnr = api.nvim_get_current_buf() - local yank_ns = api.nvim_create_namespace('') api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) local pos1 = vim.fn.getpos("'[") |